Search code examples
google-hangouts

Posting a Webhook to Existing Thread


Trying to figure out how to have a post a webhook message in Hangouts Chat to an existing thread in a chat room.

When I post to the webhook URL, I get the following response:

{
    "name": "spaces/123123123123/messages/128391203812903809128",
    "sender": {
        "name": "users/u4i3u4oi32u5oi23u4o23",
        "displayName": "Mecha",
        "avatarUrl": "",
        "email": "",
        "type": "BOT"
    },
    "text": "",
    "cards": [
        {
            "header": {
                "title": "Some Title",
                "subtitle": "Some Subtitle",
                "imageStyle": "IMAGE",
                "imageUrl": "Some Image URL",
                "imageAltText": ""
            },
            "sections": [],
            "cardActions": [],
            "name": ""
        }
    ],
    "previewText": "",
    "annotations": [],
    "thread": {
        "name": "spaces/123123123123/messages/128391203812903809128"
    },
    "space": {
        "name": "spaces/123123123123",
        "type": "ROOM",
        "displayName": "Chat Room"
    },
    "fallbackText": "",
    "argumentText": "",
    "createTime": "2019-01-25T21:13:03.278543Z"
}

Is there a way to use the returned "thread" in the JSON response to post to the same thread in the chat room?


Solution

  • I figured it out. You can take the thread value in returned JSON.

    In this case, it was:

    "thread": {
            "name": "spaces/123123123123/messages/128391203812903809128"
        },
    

    And add it to the JSON, you send in your next request:

    { 
      "cards": [
        {
            "header": {
                "title": "Some Title",
                "subtitle": "Some Subtitle",
                "imageStyle": "IMAGE",
                "imageUrl": "Some Image URL",
                "imageAltText": ""
            },
            "sections": [],
            "cardActions": [],
            "name": ""
        }
     ],
      "thread": {
            "name": "spaces/123123123123/messages/128391203812903809128"
        }
    }