I'm currently working on a Custom bot for Microsoft-Teams; followed the steps described in Ms doc( https://msdn.microsoft.com/en-us/microsoft-teams/custombot ) but did not managed yet to properly send a reply on any request.
This is what my webhook handler receives when I send datas on a channel in Ms-teams, with @AgentSmith (AgentSmith is the name of my bot) :
{
"type": "message",
"id": "1503406241867",
"timestamp": "2017-08-22T12:50:41.978Z",
"localTimestamp": "2017-08-22T14:50:41.978+02:00",
"serviceUrl": "https://smba.trafficmanager.net/emea-client-ss.msg/",
"channelId": "msteams",
"from": {
"id": "29:1nxaNQeM7AaQumVmUmPaS4K0gMHZD-FtA_gnJ9xFqZXG5nlpRnsIv-uWeAWQeuKKEQXEEXbwhK4LG1oqvqinGJg",
"name": "John Doe"
},
"conversation": {
"isGroup": true,
"id": "19:a438309226204de48783042c5bfd3bd9@thread.skype;messageid=1503406241867",
"name": null
},
"recipient": null,
"textFormat": "plain",
"attachmentLayout": null,
"membersAdded": [],
"membersRemoved": [],
"topicName": null,
"historyDisclosed": null,
"locale": null,
"text": "<at>AgentSmith</at> test",
"speak": null,
"inputHint": null,
"summary": null,
"suggestedActions": null,
"attachments": [
{
"contentType": "text/html",
"contentUrl": null,
"content": "<div><span itemscope=\"\" itemtype=\"http://schema.skype.com/Mention\" itemid=\"0\">AgentSmith</span> test</div>",
"name": null,
"thumbnailUrl": null
}
],
"entities": [
{
"type": "clientInfo",
"locale": "fr-FR",
"country": "FR",
"platform": "Web"
}
],
"channelData": {
"teamsChannelId": "19:a438309226204de48783042c5bfd3bd9@thread.skype",
"teamsTeamId": "19:a438309226204de48783042c5bfd3bd9@thread.skype",
"channel": {
"id": "19:a438309226204de48783042c5bfd3bd9@thread.skype"
},
"team": {
"id": "19:a438309226204de48783042c5bfd3bd9@thread.skype"
},
"tenant": {
"id": "c41d586a-6ec1-4ce3-89ed-54a2f844c8e1"
}
},
"action": null,
"replyToId": null,
"value": null,
"name": null,
"relatesTo": null,
"code": null}
The previous json
is then sent to our platform, which computes a simple text response.
Once that response received from our platform, I just make a POST request on the following endpoint :
with the body including the computed response
{
"type": "message",
"id": "1503406241867",
"timestamp": "2017-08-22T14:01:31.352Z",
"localTimestamp": "2017-08-22T16:01:31.352+02:00",
"serviceUrl": "https://smba.trafficmanager.net/emea-client-ss.msg/",
"channelId": "msteams",
"from": {
"name": "AgentSmith",
"id": "fake string as I don t know the id"
},
"conversation": {
"isGroup": true,
"id": "19:a438309226204de48783042c5bfd3bd9@thread.skype;messageid=1503406241867",
"name": null
},
"recipient": {
"id": "29:1nxaNQeM7AaQumVmUmPaS4K0gMHZD-FtA_gnJ9xFqZXG5nlpRnsIv-uWeAWQeuKKEQXEEXbwhK4LG1oqvqinGJg",
"name": "John Doe"
},
"textFormat": "plain",
"attachmentLayout": null,
"membersAdded": [],
"membersRemoved": [],
"topicName": null,
"historyDisclosed": null,
"locale": null,
"text": "Désolé, je n'ai pas compris",
"speak": null,
"inputHint": null,
"summary": null,
"suggestedActions": null,
"attachments": [],
"entities": [
{
"type": "clientInfo",
"locale": "fr-FR",
"country": "FR",
"platform": "Web"
}
],
"channelData": {
"teamsChannelId": "19:a438309226204de48783042c5bfd3bd9@thread.skype",
"teamsTeamId": "19:a438309226204de48783042c5bfd3bd9@thread.skype",
"channel": {
"id": "19:a438309226204de48783042c5bfd3bd9@thread.skype"
},
"team": {
"id": "19:a438309226204de48783042c5bfd3bd9@thread.skype"
},
"tenant": {
"id": "c41d586a-6ec1-4ce3-89ed-54a2f844c8d0"
}
},
"action": "message",
"replyToId": "1503406241867",
"value": null,
"name": null,
"relatesTo": null,
"code": null}
The request fails as follow :
error: 0.4.0: send message error: statusCode:403, statusCodeMessage:Forbidden,
error: {
"error": {
"code":"ServiceError",
"message":"not member of thread"
}
}
Any help would be appreciated. Can't see what is wrong with the reply message I built.
By the way, isn't that weird that the recipient on the object received by my webhook handler is null?
Sorry for the late reply - didn't see this when it was posted.
You do not (and cannot) post to https://smba.trafficmanager.net/emea-client-ss.msg/ ...
You can only respond to the HTTP post to your endpoint.
That is, Teams does a POST to you, and your response contains the message object.
Here's an echo bot in node.js that illustrates the concept.
const util = require('util');
var http = require('http');
var PORT = process.env.port || process.env.PORT || 8080;
http.createServer(function(request, response) {
var payload = '';
request.on('data', function (data) {
// console.log("Chunk size: %s bytes", data.length)
payload += data;
});
request.on('end', function() {
try {
response.writeHead(200);
var receivedMsg = JSON.parse(payload);
var responseMsg = '{ "type": "message", "text": "You typed: ' + receivedMsg.text + '" }';
response.write(responseMsg);
response.end();
}
catch (err) {
response.writeHead(400);
return response.end("Error: " + err + "\n" + err.stack);
}
});
}).listen(PORT);
console.log('Listening on port %s', PORT);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.