Bot not connecting to MS Teams Channel

1.6k views Asked by At

MS BOT Framework bots not working on Microsoft teams channel. Its working fine on every other channel configured.

App ID: b3e237eb-7a3b-4b15-b8e1-4c30d1c94c77

code used:

[BotAuthentication]
public class MessagesController : ApiController
{
    /// <summary>
    /// POST: api/Messages
    /// Receive a message from a user and reply to it
    /// </summary>
    public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
    {
        if (activity.Type == ActivityTypes.Message)
        {
            ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));


            if(activity.Text.ToUpper().Contains("EMAILS") || activity.Text.ToUpper().Contains("EMAIL") ||
                activity.Text.ToUpper().Contains("MAILBOX") || activity.Text.ToUpper().Contains("OUTLOOK") )
            {
                    // return our reply to the user
                    Activity reply = activity.CreateReply($"blah .. blah ..");
                    await connector.Conversations.ReplyToActivityAsync(reply);

                    reply = activity.CreateReply($"blah .. blah ..");
                    await connector.Conversations.ReplyToActivityAsync(reply);

                    reply = activity.CreateReply($"blah .. blah ..");
                    await connector.Conversations.ReplyToActivityAsync(reply);                    }               

            }
        }
        else
        {
            HandleSystemMessage(activity);
        }
        var response = Request.CreateResponse(HttpStatusCode.OK);
        return response;
    }
}
2

There are 2 answers

9
Rich Moe - Microsoft On

Hello: I was able to add and test your bot to my Teams client. Per your sample, I entered "Mail" and got a response. Are you still seeing issues on your side?

0
sjkp On

My issue was resolved after bots was enabled in the office 365 tenant administration for Microsoft Teams. enter image description here Apparently bots until recently worked fine without this permission being set. So when MS started to enforce it, existing bots or new bots wouldn't work in Teams anymore.