当消息从SfB客户端发送到bot时,它会收到两个响应。地址标识为" sip"没有" sip"

时间:2018-01-10 06:55:38

标签: node.js botframework skype-for-business azure-bot-service

Bot Info

  • SDK平台:Node.js
  • Botbuilder版本:3.8.4
  • 活跃频道:Skype for Bussiness
  • 部署环境:Azure Bot服务,Azure应用服务

问题说明

使用Skype for Business客户端(如Android,iOS和Mac)从用户到机器人的聊天启动时,bot会从用户收到两个响应(类型:消息)。

但是在使用Windows SFB客户端时,bot只收到1个响应。

这仅适用于第一条消息(在聊天启动期间):地址-Id在第一条消息中Json是withoud sip,第二条消息是sip

var builder = require('botbuilder');

//
//other Code
//

var intents = new builder.IntentDialog()
    .onDefault((session) => {        
        session.send('Sorry, I did not understand \'%s\'.', session.message.text);
    });

以下是Bot收到的json格式的两条不同消息。

地址-Id在第一条消息中Json是withoud sip,第二条消息在地址ID中是sip

{
    "type": "message",
    "timestamp": "2017-12-22T05:18:19.4976179Z",
    "textFormat": "plain",
    "text": "hi",
    "address": {
        "id": //GUID
        "channelId": "skypeforbusiness",
        "user": {
            "id": "test@xyz.com",
            "name": "TestUserName"
        },
        "conversation": {
            "isGroup": true,
            "id": "NDJjOGUzNjcjc2lwOmJ1bWJsZWJlZUBiYW5uZXJ0ZWNoLm9ubWljcm9zb2Z0LmNvbQ=="
        },
        "bot": {
            "id": "sip:testbot@xyz.onmicrosoft.com",
            "name": "sip:text@xyz.onmicrosoft.com"
        },
        "serviceUrl": "https://webpoolbl20r04.infra.lync.com/platformservice/tgt-abcd/botframework"
    },
    "source": "skypeforbusiness",
    "agent": "botbuilder",
    "user": {
        "id": "test@xyz.onmicrosoft.com",
        "name": "TestUserName"
    }
}


{
    "type": "message",
    "timestamp": "2017-12-22T05:18:19.5601021Z",
    "textFormat": "plain",
    "text": "hi",
    "address": {
        "id": "2",
       "channelId": "skypeforbusiness",
        "user": {
            "id": "sip:test@xyz.onmicrosoft.com",
            "name": "TestUserName"
        },
        "conversation": {
            "isGroup": true,
            "id": "NDJjOGUzNjcjc2lwOmJ1bWJsZWJlZUBiYW5uZXJ0ZWNoLm9ubWljcm9zb2Z0LmNvbQ=="
        },
        "bot": {
            "id": "sip:testbot@xyz.onmicrosoft.com",
            "name": "sip:testbot@xyz.onmicrosoft.com"
        },
        "serviceUrl": "https://webpoolbl20r04.infra.lync.com/platformservice/tgt-3e269d45c99c53b8a53d91bd8610020f/botframework"
    },
    "source": "skypeforbusiness",
    "agent": "botbuilder",
    "user": {
        "id": "sip:test@xyz.onmicrosoft.com",
        "name": "TestUserName"
    }
}

1 个答案:

答案 0 :(得分:1)

取决于您实际要完成的操作...您只需检查该字段并移除sip:或在代码中添加sip:

let id = idFromJson;
let prefix = "sip:";
if (id.includes(prefix)) {
   id = id.substring(3, id.length-1);
}

let id = idFromJson;
let prefix = "sip:";
if (!id.includes(prefix)) {
   id = prefix + id;
}