通过工作流向 Google Chat 发送通知

您可以创建一个工作流,将消息发送到 Google Chat 传入的网络钩子。 通过传入的网络钩子,你可以从非 Chat 应用向 Google Chat 发送异步消息。例如,您可以配置监控应用,以便在服务器发生故障时通过 Google Chat 通知值班人员。

创建并注册 Google Chat 传入的网络钩子

在您要接收消息的 Google Chat 聊天室中,创建一个 webhook。 按照说明注册传入 webhook

向网络钩子网址发出 HTTP 调用

创建工作流,并向工作流添加一个步骤,用于对网络钩子网址进行 HTTP POST 调用。例如:

YAML

  - get_message:
      call: http.post
      args:
        url: WEBHOOK_URL
        body:
          text: "Hello world!"
        headers:
          Content-Type: "application/json; charset=UTF-8"
      result: response
  - return_value:
      return: ${response}

JSON

  [
    {
      "get_message": {
        "call": "http.post",
        "args": {
          "url": "WEBHOOK_URL",
          "body": {
            "text": "Hello world!"
          },
          "headers": {
            "Content-Type": "application/json; charset=UTF-8"
          }
        },
        "result": "response"
      }
    },
    {
      "return_value": {
        "return": "${response}"
      }
    }
  ]

WEBHOOK_URL 替换为您在注册入站 webhook 时复制的网络钩子网址。

您可以确保系统向您的 Google Chat 聊天室发送通知,以确认工作流是否按预期运行。

后续步骤