• 0

Microsoft Teams: Create a new message in a channel


Question

So I am working on setting up a new (private) bot for Microsoft Teams that should be able to post messages in a channel on-demand. I already have a bot coded for Google Hangouts Chat, but Microsoft Teams is giving me a really hard time.

I've been searching for over 10 hours now all over the web, and I am very confused.

 

Right now, all I want to do is post cards to a Microsoft Teams Channel. So I created the connectorclient, I used the baseuri provided when the bot joined the channel (Starts with smba.trafficmanager.net) with my MSAppID and MSAppPassword. Then, I fill in as much information as I can (Maybe too much?) and I submit the information using the connector's .conversations.createconversation.

 

Namespaces used: Microsoft.bot.connector, Microsoft.bot.connector.teams.models

 

Here's the code:

 

 Dim Connector As New ConnectorClient(New Uri("https://smba.trafficmanager.net/amer/"), "MSAPPID", "MSAPPPASSWORD")


        Dim conversation As New ConversationParameters
        Dim activity2 = Activity.CreateMessageActivity
        Dim bot As New ChannelAccount
        bot.Id = "BOTID"
        bot.Name = "EDD Bot Test"


        conversation.Bot = bot
        Dim chaninfo As New ChannelInfo
        chaninfo.Id = "CHANID"
        chaninfo.Name = "General"
        Dim teaminfo As New TeamInfo
        teaminfo.Id = "TEAMID"
        teaminfo.Name = "EDD"
        activity2.Text = "Test"
        activity2.ServiceUrl = "https://smba.trafficmanager.net/amer/"
        activity2.Type = ActivityTypes.Message
        activity2.From = bot
        activity2.ChannelId = "msteams"
        Dim tenantdata As New TenantInfo
        tenantdata.Id = "TENANTID"
        Dim teamschanneldata As New TeamsChannelData
        teamschanneldata.Channel = chaninfo
        teamschanneldata.Team = teaminfo
        teamschanneldata.Tenant = tenantdata
        activity2.ChannelData = teamschanneldata



        conversation.Activity = activity2
        Response.Write(JsonConvert.SerializeObject(conversation))
        Try

            Dim reqresp As ConversationResourceResponse = Connector.Conversations.CreateConversation(conversation)
            Response.Write("ActivityID: " & reqresp.ActivityId & ", ServiceURL: " & reqresp.ServiceUrl & ", ID: " & reqresp.ServiceUrl)
        Catch ex As ErrorResponseException
            Response.Write(ex.Response.Content & " " & ex.Response.ReasonPhrase)
        End Try

This is what the API returns:

 

{"message":"Authorization has been denied for this request."} Unauthorized

 

Keep in mind, I'm not even 100% sure I'm using the right method to create the channel message, I figured it was either CreateConversation or ReplyToActivity.

I gave the app Users.ReadWriteAll permissions too, so am I missing something? That error leads me to think it doesn't have anything to do with the ConversationParameters payload but something to do with authentication.

 

Thank you.

1 answer to this question

Recommended Posts

  • 1

This was fixed btw. It seems I needed to added a trust for the serviceurl.

 

Or my service url.

 

Truth be told, to hell with the specifics. It works.

 

The command that helped, to be added before the connector:

 

            MicrosoftAppCredentials.TrustServiceUrl

 

This topic is now closed to further replies.
  • Posts

    • Anyway to download these versions without being on the Experimental builds?
    • Nothing is stopping you from continuing with your testing cadence. If updates are released every 2 weeks instead of 4, and you test once every 4 weeks, the exact same amount of patches will still be available for you in those 4 weeks. For example: Before 4th week - patch 1, 2, 3, 4 After 2nd week - patch 1 and 2 4th week - patch 3 and 4 Still the same amount after 4.
    • Everyone else has said it. I'm gonna say it - you don't know what you're talking about. I do. I have two laptops. One work, one personal. I have access to two more laptops - both personal. At home I manually update my personal laptop when I see on Neowin that there is an update - I carry on and only apply the updates when I am ready. My work one only updates when my workplace decides to send it - I carry on and only apply the updates (when they actually arrive, which is usually days after the release) when I switch off the laptop at the end of the day as usual. The two other personal laptops only get updated when I get to it which is rarely - the people who own them carry on using them until I get to it and update them. All of the browsers on all laptops are configured to restore the tabs when launched. Google and Microsoft have changed from 6 weeks to 4, and it looks like it's going to move to 2. None of these changes affect how any of these browsers on the laptops are used. Not one jot. My advice to you is stop panicking whenever you see an update. Just carry on with what you're doing. This even benefits you in a way - from your comment you sound like you don't like the changes or the frivolous new features - great - then carry on as before!
    • AMAZON needs to take total accountability for this.
    • Server Summit had a heap of announcements, ADCS changes are baller.
  • Recent Achievements

    • Week One Done
      Jeroen Wilms earned a badge
      Week One Done
    • Week One Done
      rolfus earned a badge
      Week One Done
    • One Month Later
      Leroy Jethro Gibbs earned a badge
      One Month Later
    • Conversation Starter
      flexorcist earned a badge
      Conversation Starter
    • One Month Later
      AndreaB earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      509
    2. 2
      +Edouard
      198
    3. 3
      PsYcHoKiLLa
      138
    4. 4
      ATLien_0
      90
    5. 5
      Steven P.
      80
  • Tell a friend

    Love Neowin? Tell a friend!