c# - 如何使用 google Hangouts chat api webhooks 在同一线程上发布消息?

标签 c# .net-core-3.0 hangouts-api

当消息与正在处理的同一文件有关时,我尝试在同一线程中使用 webhooks 向 google chat API 发送一条消息。现在消息正在发布,但不在同一线程中。任何帮助将不胜感激。

public async Task ExecutionStarted(string fileName, string filePath)
        {
            var today = DateTime.Now.ToString("yyyyMMddTHH:mm:ss");
            string json = "{\"text\":\"" + today + ": Processing file " + fileName + " from " + filePath + "\"}";
            await PostToGoogleChat(json);
        }

public async Task PostToGoogleChat(string json)
        {
            HttpClient client = new HttpClient();
            var content = new StringContent(json, Encoding.UTF8, "application/json");
            var result = await client.PostAsync(new Uri(_chatUrl), content);
        }

最佳答案

为了响应线程,您必须在调用的 URL 中包含线程标识符。线程标识符是 parent 参数的一部分(请参阅 spaces.message.create )。

当您从 webhook 获取消息时(请参阅: message resource ,您可以从它所拥有的 thread 属性获取发布该消息的线程)。之后,在创建消息时,您只需发送该确切线程的名称(这是其标识符,应类似于 spaces/AAAAMpdlehY/threads/UMxbHmzDlr4)作为消息父级。

关于c# - 如何使用 google Hangouts chat api webhooks 在同一线程上发布消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58699896/

相关文章:

c# - 在c#中定义对象时使用

c# - 在 ASP.NET 布局中呈现 JSON 字符串

.net-core-3.0 - 在 .NET Core 中加载程序集和类型

c# - 无法解析符号 'notnull'

ios - iOS 版 Google Meet - URL 方案

c# - "Asynchronous operations are not allowed in this context"

c# - 从 C# 运行 Powershell

.net-core - 无法访问 .net Core 3 中的 resx 文件

java - 与机器人进行环聊聊天不会将消息发布到 pub/sub

validation - 聊天机器人 : how to validate incoming requests from google hangouts