0

I have a Teams Message extension that returns a Task response which is a medium sized embedded web view iFrame

  • This is working successfully; including added a custom Tab within the channel and other nice magic calls to Microsoft Graph.

What I am confused about is how to do (and this is probably my not understanding the naming of things)

  1. insert "something" Back into the Message/Post stream which is a link to newly created Tab ... like the what you get when you have a "configureTabs" style Tab created -- there is a friendly Message (Post) in the chat pointing to this new Tab.

    • do I do this with Microsoft Graph or back through the Bot?

    • the code that does the communication may be a different service elsewhere that is acting async ... so it needs to communicate with something somewhere with context. Confused if this is the Bot with some params or Microsoft Graph with params.

  2. how to insert an image (rather than a link to the tab) into the Message/Post stream -- but showing the image not a link off to some random URL (ie: )

    • could not find any samples that do this; again, will be async as per above; but the format of the message will be a Card or something custom?
Hilton Giesenow
  • 9,809
  • 2
  • 10
  • 24
NickHodge
  • 313
  • 3
  • 10

2 Answers2

0

So just to be clear, a Task Response is NOT the same as a Tab, albeit that they might end up hosted in the same backend web application (and also albeit that your TAB can actual bring up your Task Response popup/iframe using the Teams javascript library).

Aside from that, in order to post something back to the channel, like when the Tab is created, there are two ways to do so:

  1. First is to use Graph Api's Create ChatMessage option (this link is just for a channel though - not sure if your tab/task apply to group chats and/or 1-1 chats as well).
  2. 2nd Option is to have a Bot be part of your application as well. Then, when you're ready to send something to the channel, you'd effectively be sending something called a "pro-active messaging". You need to have certain reference data to do this, which you would get when the bot is installed into the channel ("conversation reference", "ServiceUrl", and so on). I describe this more in my answer at Programmatically sending a message to a bot in Microsoft Teams

With regards sending the image, either of the above would work here too, in terms of how to send the image. As to the sending of an image, you'd need to make use of one of the kinds of "Cards" (basically "richer" messages than just raw text). You can learn more about this at Introducing cards and about the types of cards for Teams at Card reference. There are a few that can be used to send an image, depending on perhaps what else you want the card to do. For instance, an Adaptive Card can send an image, some text, and an action button of some sort.

Hope that helps

Hilton Giesenow
  • 9,809
  • 2
  • 10
  • 24
0

To close the loop for future readers.

I used the following Microsoft Graph API docs, and the posting above, and this is working: Create chatMessage in a channel and Creating a Custom Microsoft Graph call from the SDK

The custom graph call (as it is not implemented in the .NET SDK at the time of this response) looks something like:

var convoReq = $"https://graph.microsoft.com/beta/teams/{groupId}/channels/{channelId}/messages";
var body = this.TeamsMessageFactory(newCreatedTabUrl, anotherstring).ToJson();
var postMessage = new HttpRequestMessage(HttpMethod.Post, convoReq)
{
   Content = new StringContent(body, System.Text.Encoding.UTF8, "application/json")
};
await _graphClient.CurrentGraphClient.AuthenticationProvider.AuthenticateRequestAsync(postMessage);
var response = await _graphClient.CurrentGraphClient.HttpProvider.SendAsync(postMessage);

if (response.IsSuccessStatusCode)
{
     var content = await response.Content.ReadAsStringAsync();
     return true;
}

The groupId and channelId are found elsewhere; and the TeamsMessageFactory is just some boilerplate that serialized the C# object graph for the POST request, as detailed in Create chatMessage in a channel

NickHodge
  • 313
  • 3
  • 10