A
A
Andrey L2017-04-16 20:11:03
Skype
Andrey L, 2017-04-16 20:11:03

How to send a response from a bot via Skype API v3?

Good afternoon!
Experimenting with skype bots. I can't figure out how to respond via API 3rd version to a chat with a bot.
Those. on test communication, I send a message to my bot, accept it, in the form of JSON, which looks like this in an array:

Array
(
    [type] => message
    [id] => 182c7|0000001
    [timestamp] => 2017-04-03T09:02:34.5815073Z
    [serviceUrl] => https://webchat.botframework.com/
    [channelId] => webchat
    [from] => Array
        (
            [id] => u…qG
            [name] => You
        )

    [conversation] => Array
        (
            [id] => 18bc…2c7
        )

    [recipient] => Array
        (
            [id] => p…[email protected]…r-M
            [name] => П…о
        )

    [textFormat] => plain
    [locale] => ru-RU
    [text] => Привет!
    [channelData] => Array
        (
            [clientActivityId] => 149125196.0
        )

)

And I can not understand what to send him in response. For example, in Telegram, a JSON response is generated and returned, in VK a GET response is generated, in WeChat an XML response is generated.
And how to answer skype? Does anyone have a code example? Or maybe you poke your nose, where is the answer in mana?
UPD: No one answered, I decided myself, the solution is in the comments.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey L, 2017-04-18
@compudza

<?php

// Получаем токен, он живет 3600 сек, можно кешировать
/*
  "token_type": "Bearer",
  "expires_in": 3599,
  "ext_expires_in": 0,
  "access_token": "eyJ0eXAiOi..."
*/
$url='https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token';
$params=array
    (
    'client_id' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx', //your-app-id
    'client_secret' => 'xxxxxxxxxxxxxxxxx',          // your-app-secret
    'grant_type'=>'client_credentials',                     //client_credentials&
    'scope'=>'https://api.botframework.com/.default'
    );
$result=file_get_contents($url, false, stream_context_create(array('http' => array
    (
    'method' => 'POST',
    'header' => 'Content-type: application/x-www-form-urlencoded',
    'content' => http_build_query($params)
    ))));

$token = json_decode($result, TRUE);

// Соответствия входящему массиву из вызова
// $IN['CHANNEL_NAME']
// $IN['CHANNEL']  = ['conversation']['id']
// $IN['URL'] = ['serviceUrl']
// $IN['TO'] = ['recipient']['id']
// $IN['FROM_ID'] = ['from']['id']

$url =$IN['URL'].'/v3/conversations/'.$IN['CHANNEL'].'/activities/';
$data_string = '
{
  "type": "message",
  "from": {
    "id": "'.$IN['TO'].'",
    "name": "Echo Bot"
  },
  "conversation": {
    "id": "'.$IN['CHANNEL'].'"
  },
  "recipient": {
    "id": "'.$IN['CHANNEL'].'",
    "name": "User Name"
  },
  "text": "'.$OUT['MSG'].'",
  "replyToId": "'.$IN['FROM_ID'].'"
}
';

$ch = curl_init($url);                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',
  'Authorization: Bearer '.$token['access_token'].'',
    'Content-Length: ' . strlen($data_string))                                                                       
);        

$result = curl_exec($ch); // должен вернуть {"id":"0:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question