I am using teams toolkit version 4 and I created an app with two tabs. One is a notification bot configured with restify and other one is tab. The notification bot did install with adaptive cards as I wanted adaptive cards only. This is not a problem. But,I cannot quite find a way to fire the first welcome adaptive card in the notification bot automatically.
This is my botActivityHandler.js file
For development , I used the Invoke web request API and issued from my powershell to see the first welcome adaptive card.
This is the index.js file
Finally this is the init file
Any suggestions how can a display the the welcome card everytime user switches tabs and selects the notificiation bot tab
This is the folder structure for my bot
I tried reading documentation but it is not give a clear pointer to how to achieve this and I cannot find anything about this on the internet at any other source either. Every solution I see is using powershell parallely to manually send requests to see the adaptive card. I want this for the user to happen but not manually. So, they do not have to have a command line and powershell to execute rest api request.
The Bot Framework SDK supports welcome message that you may need to implement your own TeamsActivityHandler
and its onMembersAdded
method.
If your app is created via Teams Toolkit, probably you already have following code:
/// initialize.ts
const bot = new ConversationBot...
/// index.ts
server.post("/api/messages", async (req, res) => {
await bot.requestHandler(req, res);
});
To add welcome message, you may need to add your own TeamsActivityHandler
:
/// myBot.ts
class MyBot extends TeamsActivityHandler {
constructor() {
...
this.onMembersAdded = ...
}
}
Then, use it to handle bot event:
/// init somewhere
const bot = new ConversationBot...
const myBot = new MyBot...
/// The "/api/messages" handler
server.post("/api/messages", async (req, res) => {
await bot.requestHandler(req, res, async (context) => {
await myBot.run(context);
});
});
You can find more welcome message samples from the Bot Framework SDK document.
And there's also another question about adding welcome message to notification bot.
The BotActivityHandler
implementation looks right, but it seems something wrong in index.js
:
bot.adapter.process(req, res, ...
instead of bot.adapter.processActivity(req, res, ...
?req.body
and context.activiy.text
to see if received message is correctserver.post("/api/messages", async (req, res) => {
/// log req.body ...
bot.adapter.process(req, res, async(context) => {
/// log context.activity.text ...
await botActivityHandler.run(context);
});
});