I'm trying to get a bot to reply to an existing conversation through a separate function. My code looks as follows.
class TestClass():
def callback(self, message):
async def async_callback(turn_context):
await turn_context.send_activity(message)
return async_callback
async def testReply(self, message):
conversation_reference = shared_storage[self.user_id]
adapter = MyBotAdapter()
await adapter.continue_conversation(conversation_reference, self.callback(message))
print("OUTTTTTTTTTTTTTTT")
class TestBot(ActivityHandler):
async def on_message_activity(self, turn_context: TurnContext):
conversation_reference = TurnContext.get_conversation_reference(turn_context.activity)
self.user_id = turn_context.activity.from_property.id
shared_storage[self.user_id] = conversation_reference
other_class = TestClass(self.user_id)
await other_class.testReply(turn_context.activity.text)
There are no errors but testReply doesn't reply at all. Any idea what is causing this?
Try this approach:
app.py:
bot.py:
This code will provide an endpoint on http://localhost:3978/api/notify (GET) that every time requested, it's gonna send a proactive notify to users that had sent messages before.
I was stuck on the same problem than you, so I cloned the botbuilder-samples repo and I've implemented this approach based on the sample botbuilder-samples/samples/bot-samples/16.proactive-messages on the repo.
Here's the link of the github repo where this code was based, and here's the contributing Microsoft documentation.