0

I'm currently trying to figure out how I should be able to send messages to a group chat that the bot exist in. I have the conversation id (as I can save it when the bot joins) but I can't figure out how I should get the actual group name (as I want to be able to map name and conversation id).

If I check on the turn context on any of the event trigger (OnMembersAdded, OnMessageActivity, etc) it have a couple of name properties but they are always null (but isGroup is true so it at least have that right).

Then I thought I maybe could go through the connector client but it doesn't have any available methods for this at all. The closest I found was GetConversationsWithHttpMessagesAsync but it don't contain any useful information.

var connectorClient =  new ConnectorClient(
            new Uri(serviceUrl),
            new MicrosoftAppCredentials(
                _accessConfiguration.MicrosoftAppId,
                _accessConfiguration.MicrosoftAppPassword,
                _accessConfiguration.MicrosoftAppTenantId,
                null))

connectorClient.Conversations.GetConversationsWithHttpMessagesAsync() // This one doesn't contain any extra info about the conversation

So my question is, have anyone managed to get this group chat name and how did you do it?

enter image description here

MilleB
  • 1,470
  • 2
  • 19
  • 32
  • I'm not sure I fully answered your question about getting the conversation or chat based on name, so just let me know in the comments below the answer, and please clarify the scenario so I can better understand. – Hilton Giesenow Dec 30 '22 at 11:54

1 Answers1

0

What you're wanting to do (send a message whenever you like, proactively, to the channel rather than in reply to a message) is definitely possible, and it's actually called "Proactive Messaging". I've answered lots of question on it over time, but here's quite a complete answer you can refer to: Sending proactive messages from an outside process to organizational users via Teams chat bot

However, that's separate from finding out -which- chat or channel to message. I would advise against storing the channel or chat name though, because it can change - rather just use the ID. I'm not clear why this is important for you though. If you are doing it because, for instance, you want the user to pick which chat to send the message to, then you can maybe give the user a form or similar where they can choose the target, and you get those based on Graph for example (see here for instance: https://learn.microsoft.com/en-us/graph/api/chat-list?view=graph-rest-1.0&tabs=http).

Hilton Giesenow
  • 9,809
  • 2
  • 10
  • 24
  • Yeah I have been reading a lot of guides on proactive messaging and it works fine now to send message to users from their conversation id. But as a next step I want to be able to send message to specific group chat messages and while I can save the conversation Ids for those as well I want an easier way to keep track of them. So for example say that the bot joins a chat named "My chat" then I want to save the name + conversation id. Then I can later use the chat name to get the conversation id which makes it easier when I want to send messages to specific chats. – MilleB Dec 30 '22 at 12:42
  • So one problem there is that the conversation name might change, and then you'd be stuck. Are you showing these names to the user, to allow them to choose the conversation? – Hilton Giesenow Dec 30 '22 at 12:43
  • If not, how are you choosing which conversation to send to? – Hilton Giesenow Dec 30 '22 at 12:43
  • The thing is that at my current job we have some big chat rooms (100+ users) that are pretty static and while it is a chance that the name may change in the future they will probably stay the same. So the goal was simply to map the conversation ID connected to these big chat rooms to their name in a database. So instead of using the conversation id they could simply say that they wanted to send a message to this chat name instead (which then use the conversation id under the hood). But as it may not be an easy way to get the chat room name I think I will just map them manually instead. – MilleB Dec 30 '22 at 12:53
  • If they're pretty static then, as you say, a manual mapping is probably fine. – Hilton Giesenow Dec 30 '22 at 13:53