1
votes

I am attempting to send a message to a Teams Channel from within a proactive 3rd party WebHook callback that resides in my Teams Bot which is triggered externally some time after my bot conversation has ended.

My config.ServiceURL is 'https://smba.trafficmanager.net/amer/' which I got from my bot while conversing in a session.

My config.MicrosoftAppId value is the ApplicationID assigned to my bot App registration in Azure.

My config.MicrosoftAppPassword is a Client secret I created for the registered bot App.

My ChannelInfo value is the value I discovered by enumerating all the target team's channels in another application. I replaced the actual values with 'f's.

In Azure I added the following permission to my registered App: Delegate - Group.ReadWrite.All

When I attempt to create the conversation I get a Forbidden response. If I change my ChannelInfo below to a bogus value I receive a Not Found response as expected so at least the ChannelInfo appears to be a valid value.

Is there another permission I need to add? Have I missed step? Is there something I did wrong?

Here is the code:

        AuthenticationConfig config = AuthenticationConfig.ReadFromJsonFile("appsettings.json");

        var credentials = new MicrosoftAppCredentials(config.MicrosoftAppId, config.MicrosoftAppPassword);

        if (!MicrosoftAppCredentials.IsTrustedServiceUrl(config.ServiceURL))
        {
            MicrosoftAppCredentials.TrustServiceUrl(config.ServiceURL);
        }

        var serviceUri = new Uri(config.ServiceURL);
        var botConnector = new ConnectorClient(serviceUri, credentials);


        Activity message = (Activity)Activity.CreateMessageActivity();
        message.Text = "Hello World";

        var conversationParameters = new ConversationParameters
        {
            Bot = message.From,
            IsGroup = true,
            ChannelData = new TeamsChannelData
            {
                Channel = new ChannelInfo("19:[email protected]")
            },
            Activity = (Activity)message
        };


        var conversationResponse = await botConnector.Conversations.CreateConversationAsync(conversationParameters);

        await botConnector
           .Conversations
           .SendToConversationAsync(message);
1

1 Answers

0
votes

Your code worked fine for me. Here's a few things you can try:

  1. Ensure you sideloaded your bot into Teams via App Studio or manifest upload and that you're not just talking with the bot by appId
  2. Ensure your bot is installed to the Team you want it to message
  3. Add the domain your bot is hosted on to the Valid Domains section of the bot manifest
  4. Esure you're sending the message to the correct conversation by changing .SendToConversationAsync(message); to .SendToConversationAsync(conversationResponse.Id, message);

Also note that the Microsoft.Bot.Builder.Teams package has been deprecated now that Bot<->Teams functionality has been rolled directly into the Bot Framework SDK. I highly recommend migrating away from it.

You may want to send proactive messages as shown in this sample. The other Teams Samples are numbers 50-60.


Let me know if you want to stick with that package and I can continue trying to provide support.