机器人收到重复的卡片点击事件

Bot receiving duplicate card click events

我正在使用以下库将机器人连接到 Google Pub/Sub 端点以对卡片点击事件执行简单回复。

Google.Apis.HangoutsChat.v1 1.34.0.1233

Google.Cloud.PubSub.V1 1.0.0-beta18

当我构建卡片时,UI 中的一切看起来都很正常,包括应该引发事件的按钮。

主题和订阅包含默认设置,遵循指南here

我从 Google 文档中找到了有关重试的以下信息 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.

单击按钮后,我的订阅者收到 3 个重复事件。这些事件具有所有正确元数据的正确响应,但彼此完全相同,包括消息本身的 ID。

我觉得机器人的响应不一定有很大的延迟(对于这个测试应该在 <1 秒内发生),所以我不确定为什么这些消息会被重复。

我也试过在响应时设置卡片的线程 ID(通过 Thread 属性 本身,或者 ThreadKey 属性),但是我当我 post 一条消息时,似乎总是得到一个新的线程 ID。

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

有趣的是,尝试创建新消息以响应单击事件会导致机器人显示 "Unable to connect to bot. Try again later",但显示 3 条新消息。此外,当指定任意线程键时,该键永远不会在机器人的响应中回显。

确保您正确返回主要 event 方法。看起来正在发生的事情是您正在对聊天进行异步调用,但随后聊天正在寻找来自实际事件方法本身的响应。 Google 通常会在放弃前尝试 三次 次(即使不需要三十秒)

如果您在发出 api 请求后确实正确地返回了事件调用,那么您的代码中有些东西导致 Google 机器人认为它没有得到响应,所以它尝试了 3 次。由于问题可能是多方面的,我需要看看您是如何接受和返回点击响应的。

此错误最终已被 Google 修复。