Reputation: 5235
I would like to start a conversation with a user without that he already chatted with the bot.
I'm proceeding bu getting the conversationId
when user install the bot app as mentionned here
Here how I catch reference
and serviceUrl
by using processActivity
event
Then I use 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;
};
I'm getting this error
Error: BotFrameworkAdapter.sendActivity(): missing serviceUrl.
I have checked the turnContext.activity
values. I get :
{"type":"event","name":"continueConversation"}"
all other values are undefined ( serviceUrl also )
I noticed that turnContext.activity
inside adapter.processActivity
is not the same as in adapter.continueConversation
and have all the serviceUrl
and conversationId
How can I edit this code example to be able to send proactive messages to users?
Upvotes: 0
Views: 698
Reputation: 121
The const reference needs to be ConversationReference not just the Id if you are using it for BotFrameworkAdapter.continueConversation().
A ConversationReference can be retrieved by using:
const reference = TurnContext.getConversationReference(turnContext.activity);
Upvotes: 2