直线连接角色和名称未进入 BOT conversationUpdate
directline connection role and name not getting in BOT conversationUpdate
//供参考-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、name、role。在“from”中,对象名称和角色键丢失//并且存在 id 但自动生成的 id 不是实际的用户 id myid。
您没有获得用户的 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);
});
我已经在我的代码中应用如下,它有帮助。可能对其他人有用
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));
它会触发两次机器人activity,一次没有用户信息,一次有用户信息。所以我确实在机器人端检查了用户信息是否包含名称 kay 然后加载我的初始对话框如下所示......它对我有用。谢谢@mdrichardson
if (membersAdded[cnt].id === context.activity.recipient.id && context.activity.from && context.activity.from.name
&& context.activity.channelId=='directline') {
await dialog.run(context, conversationState.createProperty('DialogState'));
}
//供参考-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、name、role。在“from”中,对象名称和角色键丢失//并且存在 id 但自动生成的 id 不是实际的用户 id myid。
您没有获得用户的 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);
});
我已经在我的代码中应用如下,它有帮助。可能对其他人有用
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));
它会触发两次机器人activity,一次没有用户信息,一次有用户信息。所以我确实在机器人端检查了用户信息是否包含名称 kay 然后加载我的初始对话框如下所示......它对我有用。谢谢@mdrichardson
if (membersAdded[cnt].id === context.activity.recipient.id && context.activity.from && context.activity.from.name
&& context.activity.channelId=='directline') {
await dialog.run(context, conversationState.createProperty('DialogState'));
}