Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用google hangouts聊天api webhooks在同一线程上发布消息?_C#_.net Core 3.0_Hangouts Api - Fatal编程技术网

C# 如何使用google hangouts聊天api webhooks在同一线程上发布消息?

C# 如何使用google hangouts聊天api webhooks在同一线程上发布消息?,c#,.net-core-3.0,hangouts-api,C#,.net Core 3.0,Hangouts Api,我试图在同一个线程中使用webhooks向google聊天API发送一条post消息,而该消息与正在处理的文件大致相同。现在消息正在发布,但不在同一线程中。任何帮助都将不胜感激 public async Task ExecutionStarted(string fileName, string filePath) { var today = DateTime.Now.ToString("yyyyMMddTHH:mm:ss"); st

我试图在同一个线程中使用webhooks向google聊天API发送一条post消息,而该消息与正在处理的文件大致相同。现在消息正在发布,但不在同一线程中。任何帮助都将不胜感激

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中包含线程标识符。线程标识符是
父级
参数的一部分(请参阅)


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

当您发送第一条消息时,您将收到一个响应json,在该响应中,您将收到一个
thread
属性。您必须使用此
线程
属性在与文本和/或卡片相同的级别上发送新消息

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 + "\"}";
            if(this.currentThread){
                json.thread = this.currentThread
            }
            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);
            this.currentThread = result.thread
        }

根据这些文档,只需将threadKey添加到查询参数中

相同的线程键将转到相同的线程,无需记住上一篇文章中的线程ID

您的请求url将如下所示
.

任何Post消息响应都将包含在响应负载中

"thread": {
    "name": "spaces/AAAASchux4w/threads/GgWXNtFDOpE"
}
您需要做的是在将来希望在同一线程中发送的任何消息中包含这一点

{
    "text": "message in the same thread",
    "thread": {
        "name": "spaces/AAAASchux4w/threads/GgWXNtFDOpE"
     }
}

嘿@MJ9094你能解决你的问题吗?我很想听一听。谢谢