question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No ActivityHandler events raised for new messages in group chats with bot installed

See original GitHub issue

Version

4.14.1

Describe the bug

I created a group chat and installed my bot into it. I can post proactively using a connectorclient, and I get events for participants being added and removed, but there are no activities raised for new messages in the chat thread.

To Reproduce

Using graph, create a group chat and add a bot like this:

                Chat c = new Chat
                {
                    ChatType = ChatType.Group,
                    Topic = "Group chat:" + Guid.NewGuid(),
                    Members = new ChatMembersCollectionPage()
                    {
                        new AadUserConversationMember
                        {
                            Roles = new List<String>()
                            {
                                "owner"
                            },
                            AdditionalData = new Dictionary<string, object>()
                            {
                                {"user@odata.bind", "https://graph.microsoft.com/v1.0/users/"+ userID}
                            }
                        },
                        new AadUserConversationMember
                        {
                            Roles = new List<String>()
                            {
                                "owner"
                            },
                            AdditionalData = new Dictionary<string, object>()
                            {
                                {"user@odata.bind", $"https://graph.microsoft.com/v1.0/users/" + AppId}
                            }
                        }
                    }
                };
                //requires TeamsAppInstallation.ReadWriteForChat
                Chat resp = await m_graphClientUser.Chats.Request().AddAsync(c);
                m_chatID = resp.Id;
                var teamsAppInstallation = new TeamsAppInstallation
                {
                    AdditionalData = new Dictionary<string, object>()
                {
                    {"teamsApp@odata.bind", "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/" + catalogAppID}
                }
                };
                await m_graphClientUser.Chats[resp.Id].InstalledApps.Request().AddAsync(teamsAppInstallation);

Then, override OnTurnAsync in a bot that derives from ActivityHandler (I just left the default and set a breakpoint to inspect activities:

    public class ACSBot : ActivityHandler
    {
        public override Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default)
        {
            return base.OnTurnAsync(turnContext, cancellationToken);
        }

Note if you add/remove participants from the chat in Teams, OnTurnAsync (and the appropriate other events) will fire. Reactions to bot messages also fire events. If another user sends a message to the chat thread though, nothing is fired on the bot, so the bot can’t react to the new messages like it would in a 1:1 chat.

Expected behavior

I’d expect to get message activity for any other user message in the chat.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
chrisbardoncommented, Sep 22, 2021

@stevkan - it seems like this is by design, so at this point the only other assistance would be to amend that design so that bots installed to a group chat with chat.readwrite should get notified of all messages in the chat as they happen. It’s possible to do this with a change notification subscription, but it’s harder than it should be (I actually put together a blog post describing how to do this here)

0reactions
compulimcommented, Oct 1, 2021

Copying from https://docs.microsoft.com/en-us/learn/modules/msteams-conversation-bots/2-conversation-bots:

Group chats are non-threaded conversations between three or more people. They tend to have fewer members than a channel and are more transient. Similar to a channel, your bot will only have access to messages where it’s @mentioned directly.

Scenarios that work well in a channel will usually work as well in a group chat.

I think this is by-design and is a feature request: Bot on Teams should react/receive messages without explicit at-mentions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Messages in bot conversations - Teams
Learn how to send, receive, edit, undelete, and soft delete a message in bot conversations with suggested actions, notification, attachments ...
Read more >
MS Teams Dialog Bot Event Not Fired when message is ...
The message activity is sent successfully and the message appears in the chat bot conversation. I would also like to somehow trap the...
Read more >
Using the Slack Events API
What is the Events API? The Events API is a streamlined, easy way to build apps and bots that respond to activities in...
Read more >
Use Case - How to Create a Bot on Telegram That Responds ...
Use Case – How to create a bot on Telegram that responds to group messages. Back to User Guides Note: This guide requires:...
Read more >
Microsoft teams bot python. To use the Azure CLI to provision ...
The Teams activity handler adds support for Teams-specific events and ... If the bot has been added to some personal chats and group...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found