Context & theory
According to the docs and examples, you must save the reference to a conversation in order to restore it on demand (for instance when the server receives an HTTP request) and send a reactive message to a public channel.
So I'm doing:
- Any user mentions the bot on a channel (at
#CorpChannel
for example) - Bot stores (in particular I'm using Azure Cosmos db) the reference of the conversation(
storage.write(storeItems)
) - [later] Bot receives an HTTP request that means: "send 'hi there' to #CorpChannel"
- Bot restores the conversation reference and uses it for creating a
TurnContext
in order to callsendActivity()
Problem
The activity 'hi there' is replying to the original mention to my bot instead of starting a new thread/conversation over that channel. I want to start a new fresh conversation at #CorpChannel
Visually:
Jane Doe: --------------
| @MyBot 09:00AM |
------------------------
Jhon Doe: --------------
| what ever 10:00AM |
------------------------
HTTP request: "send 'hi there' to #CorpChannel"
Jhon Doe: --------------
| whatever 10:00AM |
------------------------
Jane Doe: --------------
| @MyBot 09:00AM |
------------------------
|> MyBot: -----------
| Hi there 11:00AM |
--------------------
What I've tried
This is the code where I'm sending the activity on demand
server.post("/api/notify", async (req, res) => {
const channel = req.body.channel;
const message = req.body.message;
const conversation = await bot.loadChannelConversation(channel);
if (!conversation) { /* ... */ }
await adapter.continueConversation(conversation, async (context) => {
await context.sendActivity(message);
});
return res.send({ notified: { channel, message } });
});
this is the code where I'm going to db
// (storage) is in the scope
const loadChannelConversation = async (key) => {
try {
const storeItems = await storage.read(['channels']);
const channels = storeItems['channels'] || {};
return channels[key] || null;
} catch (err) {
console.error(err);
return undefined;
}
};
how can I post a new message instead of replying to the original thread?
==== EDIT ====
I've tried also to use createConversation()
method from the SDK, but as it says in the documentation:
The Bot Connector service supports the creating of group conversations; however, this method and most channels only support initiating a direct message (non-group) conversation.
It starts a new conversation with the original user that posted the first message in private