gpt4 book ai didi

javascript - Bot Framework v4 - 发起与用户的聊天(主动消息)

转载 作者:行者123 更新时间:2023-12-03 05:36:16 26 4
gpt4 key购买 nike

我想在用户尚未与机器人聊天的情况下开始与他对话。

当用户将机器人应用程序安装为 mentionned here 时,我将继续获取 conversationId

这里是我如何使用processActivity事件捕获referenceserviceUrl

然后我使用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 也是如此)

我注意到 adapter.processActivity 中的 turnContext.activityadapter.continueConversation 中的不同,并且具有所有 serviceUrlconversationId

如何编辑此代码示例以便能够向用户发送主动消息?

最佳答案

如果您将 const 引用用于 BotFrameworkAdapter.continueConversation(),则它必须是 ConversationReference 而不仅仅是 Id。

可以使用以下方式检索 ConversationReference:

const reference = TurnContext.getConversationReference(turnContext.activity);

https://learn.microsoft.com/en-us/javascript/api/botbuilder/botframeworkadapter?view=botbuilder-ts-latest#continueconversation-partial-conversationreference----context--turncontext-----promise-void--

https://learn.microsoft.com/en-us/javascript/api/botbuilder-core/turncontext?view=botbuilder-ts-latest#getconversationreference-partial-activity--

关于javascript - Bot Framework v4 - 发起与用户的聊天(主动消息),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62311265/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com