我想与用户开始对话,而无需他已经与机器人聊天。
当用户将机器人应用安装为mentionned here时,我将继续获取conversationId
这是我如何通过reference
事件来捕捉serviceUrl
和processActivity
然后我使用continueConversation
+ reference
const {
BotFrameworkAdapter,
} = require('botbuilder');
const adapter = new BotFrameworkAdapter({
appId: "xxxx",
appPassword: "xxxxy"
})
module.exports = async function(context, req) {
console.log(adapter);
try {
adapter.processActivity(req, context.res, async (turnContext) => {
const reference = turnContext.activity.conversation.id
const serviceUrl = turnContext.activity.serviceUrl
await adapter.continueConversation(reference, async (turnContext) => {
try {
await turnContext.sendActivity("this is proacive message");
} catch (e) {
console.log(e)
}
});
});
} catch (e) {
console.log(e)
}
return;
};
我遇到此错误
Error: BotFrameworkAdapter.sendActivity(): missing serviceUrl.
我已经检查了turnContext.activity
值。我得到:
{"type":"event","name":"continueConversation"}"
所有其他值都是未定义的(也是serviceUrl)
我注意到turnContext.activity
内部的adapter.processActivity
与adapter.continueConversation
中的serviceUrl
和conversationId
都相同
如何编辑此代码示例,以便能够向用户发送主动消息?
答案 0 :(得分:2)
如果将const引用用于BotFrameworkAdapter.continueConversation(),则const引用不仅需要是ID,还需要是ConversationReference。
可以使用以下方法检索ConversationReference:
const reference = TurnContext.getConversationReference(turnContext.activity);