Search code examples
c#google-hangouts

Bot receiving duplicate card click events


I am using the following libraries to connect a bot to a Google Pub/Sub endpoint to perform a simple reply to a card click event.

Google.Apis.HangoutsChat.v1 1.34.0.1233

Google.Cloud.PubSub.V1 1.0.0-beta18

When I construct my card, everything looks normal in the UI, including the button that is supposed to raise the event.

The topic and subscription contain the default settings, following the guide here

I found the following information from the Google documentation about retries here

Responding synchronously

A bot can respond to an event synchronously by returning a JSON-formatted message payload in the HTTP response. The deadline for a synchronous response is 30 seconds.

A synchronous response from a bot is always posted in the thread that generated the event to the bot.

After clicking the button, my subscriber receives 3 duplicate events. The events have the correct response with all of the right metadata, but are exact duplicates of each other, including the id of the message itself.

I don't feel there is a necessarily large delay in the response of the bot (it should happen in <1 second for this test), so I am not sure why these messages are being duplicated.

I've also tried setting the thread id for the card when responding (via the Thread property itself, or the ThreadKey property), but I always seem to get a new thread id when I post a message.

var cardMessage = MessageSender.Spaces.Messages.Create(new Message()
{
    Space = new Space()
    {
        Name = inReplyToThisMessage.Space.Name
    },
    Thread = new Thread()
    {
        Name = inReplyToThisMessage.Thread.Name
    },
    Cards = new List<Card>()
    {
        card
    },
}, inReplyToThisMessage.Space.Name);

var sendCardResult = await cardMessage.ExecuteAsync().ConfigureAwait(false);
//Thread id of sendCardResult does not match inReplyToThisMessage.Thread.Name no matter what

Interestingly enough, trying to create a new message in response to the click event causes the bot to display a "Unable to connect to bot. Try again later", but displays 3 new messages. Also, when specifying an arbitrary thread key, this key is never echoed back in the bot's response.


Solution

  • This bug has finally been fixed by Google.