直线连接角色和名称未参与BOT对话更新

时间:2020-06-22 11:44:34

标签: web-chat

//以下为参考-DirectLine连接代码

```(async function() {
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({
secret: “My KEY”}),
userID : "myid",
username: "myName"
},
document.getElementById('chat_converse')
);
document.querySelector('#chat_converse > *').focus();
})().catch(err => console.error(err));```

//一旦连接。 BOT中将包含以下对象。

```{
"type": "conversationUpdate",
"id": "ERqgImAulq3",
"timestamp": "2020-06-18T07:07:03.448Z",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "AicCk0YN2Ap9n2Ev1ovbuc-k"
},
"conversation": {
"id": "AicCk0YN2Ap9n2Ev1ovbuc-k"
},
"recipient": {
"id": "BotName@xp113vQdWDM",
"name": "BotName"
},
"membersAdded": [
{
"id": "BotName@xp113vQdWDM",
"name": "BotName"
}
]
}```

//从-我们应该获得ID,名称,角色。在“发件人”中,缺少对象名称和角色键//和存在ID,但使用自动生成的ID而不是实际用户ID myid。

2 个答案:

答案 0 :(得分:0)

您没有为用户得到ConversationUpdate,只有机器人。您需要send a ConversationUpdate manually


const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
   if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
     dispatch({
       type: 'WEB_CHAT/SEND_EVENT',
       payload: {
         name: 'webchat/join',
         value: { language: window.navigator.language }
       }
     });
   }

    return next(action);
  });

答案 1 :(得分:0)

我在我的代码中应用了以下内容,这很有帮助。可能对其他人有用

The text of the element.

它将触发两次时间漫游器活动,一次不带用户信息,一次带用户信息。因此,我确实在bot端检查了用户信息是否包含kay的名称,然后加载了如下所示的初始对话框。谢谢@mdrichardson

const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
      if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
        dispatch({
          type: 'WEB_CHAT/SEND_EVENT',
          payload: {
            name: 'webchat/join',
            value: { language: window.navigator.language }
          }
        });
      }

      return next(action);
    });

    window.WebChat.renderWebChat({
        directLine: window.WebChat.createDirectLine({
            secret: 'YourKey'
       }),
       userID : "UserID",
       username: "UserName",
       store
      },
      document.getElementById('chat_converse')
  );

    document.querySelector('#chat_converse > *').focus();
  })().catch(err => console.error(err));