1

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:ffffffffffffffffffffffffffffffff@thread.skype")
            },
            Activity = (Activity)message
        };


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

        await botConnector
           .Conversations
           .SendToConversationAsync(message);
JJ_Wailes
  • 2,207
  • 1
  • 9
  • 17
Mike
  • 559
  • 5
  • 21

1 Answers1

0

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.

mdrichardson
  • 7,141
  • 1
  • 7
  • 21
  • I was able to get the code to finally work but it will only post to the same Channel my Bot is running. That is it posts back to itself with is worthless to me. I was unable to push messages to other channels. Instead I have abandoned this method entirely and now instead use an application webhook to push my message to the target channel. – Mike Dec 15 '19 at 17:09
  • @Mike. I see. Unfortunately, your bot *has* to be installed to that channel in order to get the appropriate permissions to send to it. It works just like a user---a regular user can't post to a channel that they're not a part of. – mdrichardson Dec 16 '19 at 15:40