Search code examples
botsbotframeworkslack-apislack

Connecting existing Slack RTM bots to new Microsoft bot framework back end after upgrade


Sorry this is a bit long.

I have 2 versions of my bot:

Version 1.0 - based on Slack RTM back end. There are few hundred users who installed this.

Version 2.0 - based on Microsoft Bot Framework(BF) back end. a few dozen users installed this version since release a few days ago.

I have upgraded My Slack app to v2.0 to use the Bot Framework back end instead of RTM, received approval from Slack and now all new users are installing version 2.0 from the slack bot store. All good as expected.

But Once the new version of the slack app was published - I expected Slack to break the connection to the old RTM back end and connect the to the new BF back end. This did NOT happen and my few hundred users are still using the old RTM back end.

Contacted Slack support - they told me it cannot be done automatically and I need to initiate a connection for the already authenticated tokens from the BF service. How can I do that?

I tried to get the info from one of those teams and tried to send a message using the following code:

        var connector = new ConnectorClient(new Uri("https://slack.botframework.com/"));
        var conversation = new ConversationAccount(true, "B0JMAJ8C8:T0ANH2CG3:C0ANKNHU5");
        var botAccount = new ChannelAccount("B0JMAJ8C8:T0ANH2CG3", "Grasp");
        IMessageActivity message = Activity.CreateMessageActivity();
        message.From = botAccount;
        message.Conversation = conversation;
        message.ChannelId = "slack";
        message.Text = "Upgrade Test!";
        message.Locale = "en-En";
        connector.Conversations.SendToConversation((Activity)message);

But SendToConversation() gives me an exception:

Authorization for Microsoft App ID 122dd7ca-xxxxx-xxxx-b679-c696e212987a failed with status code Forbidden

Is there any other way I can force a connection from BF without my users reinstalling the new version of the same bot?

Thanks in advance.


Solution

  • When users click the "Add To Slack" button an oauth flow is launched where the user grants the bot permission to their Slack team and receives a token that the bot uses to connect to Slack. There is currently no way to transfer that token from one bot to another so you'll need to get the users on your V1 bot rerun the "Add to Slack" oauth flow to switch to V2.