Search code examples
c#azurebotframework

Restarting conversation state for testing proactive messages


I've implemented proactive messages into my bot, however I'm very unsatisfied with the testing I've been able to do with this feature, since none of the tests I can think of actually "prove" I received a message proactively.

Basically, I want to send a message to members on Teams as soon as they install the bot, not as soon as they interact with it as is the traditional way. This is so when a member is added to an organisation, they are introduced to the bot without any user interaction.

To do this, I overrode OnTeamsMembersAddedAsync, and used that event to fire off a welcome message. When it comes to testing however, I can never be sure the welcome message fired because I opened the chat window, or because I installed the app.

For this reason, I cannot test it in the emulator, as that takes you straight to the chat which defeats the point. And I'm limited to 1 test per user account in Teams, because after you install the bot once, your conversation state is cached so it's never truly a fair test after the first interaction.

So my question is, is there any code that can clear my conversation, and re-add me so as to trigger OnTeamsMembersAddedAsync as if I'm a new user being added to the org? Or is there a better way of testing I haven't thought of?


Solution

  • In case anyone stumbles upon this asking the same question I am, I'll give you my solution, although it may be unavailable to the more casual dev that doesn't have resources behind them.

    So my solution to this was to purchase a partner licence for Microsoft Power Apps, in there I can spin up sandbox environments for ms teams, which creates a whole environment in the context of a microsoft 'dataverse'. From there I could perform the tasks of an admin, and the tasks of the user and perform my tests all from 2 sandbox teams portals.

    This is a bit more of an overkill solution than what I wanted, as the licence is not easy to get and grants me power to do lots of things I don't ever see myself doing, but it did indeed solve my issue.