dongre6404 2017-05-23 09:07
浏览 120

如何通过PHP连接和发送消息给skype bot?

i want to bild a simply skype bot via php for send and recive massage im tired for serch but cannot find any true sdk or complated sample for this

im need help after get token from https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token

now i have my token and sed realtime and always send this with my requests .

but im not undrestand and fine what is any way for send massage ? what is send massage parameters ? what is send massage post link ?

i have this error: The page cannot be displayed because an internal server error has occurred.

pls help me and send completed or true sdk to work !

im rtying avry sdk in git or google no find my answer ..

thanks .

  • 写回答

1条回答 默认 最新

  • dongyu9894 2017-06-14 08:13
    关注

    Hi this is my bot script , with this i can get token and send realtim just i dont known what is next step for send msg or what is my script problem ?

    i useing 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));
    

    im use this link https://blogs.msdn.microsoft.com/tsmatsuz/2016/08/19/build-skype-bot-with-microsoft-bot-framework-oauth-and-rest-api/

    评论

报告相同问题?

悬赏问题

  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)