【问题标题】:Microsoft-Teams custom bot : error while sending a replyMicrosoft-Teams 自定义机器人:发送回复时出错
【发布时间】:2017-12-05 09:45:47
【问题描述】:

我目前正在为 Microsoft-Teams 开发自定义机器人;遵循 Ms doc(https://msdn.microsoft.com/en-us/microsoft-teams/custombot) 中描述的步骤,但尚未设法正确发送任何请求的回复。

这是我的 webhook 处理程序在我使用 @AgentSmith 在 Ms-teams 的频道上发送数据时收到的内容(AgentSmith 是我的机器人的名称):

{
"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}

然后将之前的json 发送到我们的平台,该平台计算一个简单的文本响应。

一旦从我们的平台收到响应,我只需在以下端点上发出 POST 请求:

https://smba.trafficmanager.net/emea-client-ss.msg/v3/conversations/19:a438309226204de48783042c5bfd3bd9@thread.skype;messageid=1503406241867/activities/1503406241867

正文包括计算出的响应

{
"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}

请求失败如下:

error: 0.4.0: send message error: statusCode:403, statusCodeMessage:Forbidden, 
error: {
  "error": {
      "code":"ServiceError",
      "message":"not member of thread"
  }
}

任何帮助将不胜感激。看不到我建的回复消息有什么问题。

顺便说一句,我的 webhook 处理程序接收到的对象上的接收者为 null 不是很奇怪吗?

【问题讨论】:

    标签: node.js rest microsoft-teams


    【解决方案1】:

    抱歉回复晚了 - 发布时没有看到。

    您没有(也不能)发帖到https://smba.trafficmanager.net/emea-client-ss.msg/...

    您只能将 HTTP 帖子响应到您的端点。

    也就是说,Teams 会向您发送 POST,并且您的响应包含消息对象。

    这里有一个 node.js 中的 echo bot 来说明这个概念。

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

    【讨论】:

      猜你喜欢
      • 2019-11-15
      • 2021-06-07
      • 2020-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-07
      相关资源
      最近更新 更多