在Google聊天中创建新线程-您如何发送新的指定线程密钥?

问题描述 投票:0回答:1

我正在创建一些简单的Bot函数来创建线程并将消息发送到Chat。创建“任意”线程并将消息插入具有已知ID的线程中很好,没问题,我只是无法在创建新线程时指定线程ID。我已遵循Google文档中的详细信息,但其中任何一个都无法使用。

参见:https://developers.google.com/hangouts/chat/how-tos/bots-develop

这是我的代码-非常简单,但模糊不清

$("#fa-comment").click(function() {
    $.ajax({
        method: 'POST',
        url: 'https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?key=KEY_ID&token=TOKEN_ID',
        dataType: "json",
        contentType: "application/json; charset=UTF-8",
        //data: "{'text':'This creates a new thread and inserts message - thread id is not known'}",
        //data: "{'text':'This inserts into a current thread with known id', 'thread':{'name':'spaces/SPACE_ID/threads/THREAD_ID'}}",
        success: function () {
            $('.response').html('Success');
        }
    });
})

被注释掉的data:行均正常工作。

我尝试过:

  • [data: "{'text':'This inserts into a new thread with specified id', 'thread':{'name':'spaces/SPACE_ID/threads/SPECIFIED_THREAD_ID'}}",,但会导致500错误]
  • [https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?\ threadKey=ARBITRARY_STRING如文档中所写,但没有变化,可以得到400个错误和冲突/未知变量'threadkey']

我已经尽我所能从文档中尝试各种尝试,但都无济于事。

毫无疑问,我在这里错过了一些东西,但我看不到。任何帮助都会使我的头发再次长出!

jquery json chatbot google-chat
1个回答
0
投票

我相信您可能已经解决了这个问题,但是无论如何...

查询参数应为thread_key,而不是threadKey。因此,在您的情况下,它将是:

url: 'https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?key=KEY_ID&token=TOKEN_ID&thread_key=THREAD_KEY'

希望这对以后的某人有用:)。

© www.soinside.com 2019 - 2024. All rights reserved.