[JS] Proactive messages usage #1989
-
|
I'm trying to use app.sendProactiveActivity to send a message to the user (1:1 chat), based on the conversationReference I have stored before. I would like to add a new route to the backend (different from /api/messages) to send the proactive message when this endpoint is called as a webhook from an external system. When using only app.sendProactiveActivity with the following code: I'm getting the following error message: When trying to wrap the call in a adapter.process call this way: I'm getting the following error message: What should I do? Bonus question: in which event would you store the conversationReference for future use?
cc @yiqing-zhao and @MuyangAmigo as you seem to work on a RestifyNotiBot :-) Thanks a lot |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Hey Benjiiim, for your first error, your app should be configured with an // Create adapter.
// See https://aka.ms/about-bot-adapter to learn more about how bots work.
export const adapter = new TeamsAdapter(
{},
new ConfigurationServiceClientCredentialFactory({
MicrosoftAppId: process.env.BOT_ID,
MicrosoftAppType: process.env.BOT_TYPE,
MicrosoftAppTenantId: process.env.BOT_TENANT_ID,
MicrosoftAppPassword: process.env.BOT_PASSWORD,
})
);
export const app = new Application<ApplicationTurnState>({
// Adapter and botAppId are required for the Application to send proactive messages.
adapter: adapter,
botAppId: config.MicrosoftAppId,
storage: storage,
});For your second error, there's no need to wrap the server.post(
"/api/notification",
restify.plugins.queryParser(),
restify.plugins.bodyParser(), // Add more parsers if needed
async (req, res) => {
//...
for (const reference of references) {
await app.sendProactiveActivity(
reference,
"Proactive message from RestifyNotiBot!"
);
}
res.json({});
}
);For the bonus questions, our current project stores the conversation reference when the bot is installed (in the conversationUpdate membersAdded event). In this way, the bot could send the message whenever it wishes even the user does not send a message to the bot, working just like a notification bot. However, if your case is something like the QA bot, it is also a good way to choose the second one as the botframework sample does. |
Beta Was this translation helpful? Give feedback.
-
|
We're clearing discussions and starting fresh. This discussion has not been acted upon. Please reopen the discussion, or start a new one if this question is still important. Thank you for your understanding. |
Beta Was this translation helpful? Give feedback.
Hey Benjiiim, for your first error, your app should be configured with an
adapteras follows: