如何通过PHP连接并发送按摩到skype bot?

时间:2017-05-23 09:07:11

标签: php sdk bots skype skype-bots

我想通过php bild一个简单的skype机器人发送和recive按摩 我厌倦了serch,但找不到任何真正的sdk或comprated示例

https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token

获取令牌后我需要帮助

现在我有我的令牌和sed实时,并始终发送我的请求。

但我不是不安全和精细什么方式送按摩? 什么是送按摩参数? 什么是发送按摩帖链接?

我有这个错误: 由于发生内部服务器错误,无法显示页面。

请帮助我并将完成或真正的sdk发送到工作中!

在git或谷歌中使用avry sdk找不到我的答案..

谢谢。

1 个答案:

答案 0 :(得分:1)

嗨,这是我的机器人脚本,我可以获得令牌并发送realtim 只是我不知道发送msg的下一步是什么或者我的脚本问题是什么?

我使用的是php lagn

$content = file_get_contents("php://input");
$update = json_decode($content,true);
$conversation=$update['conversation']['id'];
$user=$update['from']['id'];
file_put_contents('skype.txt',print_r($update,true));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token");
curl_setopt($ch, CURLOPT_POST, 1);

$params ="grant_type=client_credentials&";
$params.="client_id=*****************************"; // My id 
$params.="client_secret=**************************"; // My Password
$params.="scope=https://api.botframework.com/.default";

curl_setopt($ch, CURLOPT_POSTFIELDS,$params);  //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers = ['Content-Type: application/x-www-form-urlencoded'];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec ($ch);
if(curl_errno($ch)){
    var_dump(curl_error($ch));
}

$result=json_decode($result);
$access_token=$result->access_token; // now i have  access token


// what is after this step ? for send or reply msg in skype bot ?
// send request for send massage ?!
curl_setopt($ch, CURLOPT_URL,"https://skype.botframework.com/v3/conversations/".$conversation."/activities/".$user);
curl_setopt($ch, CURLOPT_POST, 1);
// what is parametr for send or reply msg ?
// what is requarement params ?
$params=array(
    'type' =>'message' , 
    'timestamp'=>$update['timestamp'],
    'from'=>array(
        'id' => $update['from']['id'], 
        'name' => $update['from']['name'], 
        ),
    'conversation'=>array(
        'id' => $update['conversation']['id'], 
        ),
    'recipient'=>array(
    'id' => $update['recipient']['id'], 
    'name' => $update['recipient']['name'], 
    ),  
    'text'=>'Wellcome to MWH',
    'replyToId' =>$user, 
);

$params=json_encode($params);
curl_setopt($ch, CURLOPT_POSTFIELDS,$params);  //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers = ['Authorization: Bearer'.$access_token];
$headers = ['Content-Type: application/json; charset=utf-8'];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$res = curl_exec ($ch);
if(curl_errno($ch)){
    var_dump(curl_error($ch));
}
curl_close ($ch);
$res=json_decode($res);

// file_put_contents('skype.txt',print_r($res,true));

即时通讯使用此链接 https://blogs.msdn.microsoft.com/tsmatsuz/2016/08/19/build-skype-bot-with-microsoft-bot-framework-oauth-and-rest-api/