Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
43
Help us understand the problem. What is going on with this article?
@mistolteen

GASからhangout chatにPostする

More than 3 years have passed since last update.

準備

WebhookのURLを取得する

チャットルームでWebhookを設定しWebhookURLを取得します。

chat1.png
chat2.png

投稿する

リファレンスのサンプルはPythonで書かれていますがこれをGASで書きます。
https://developers.google.com/hangouts/chat/quickstart/incoming-bot-python#step_2_create_the_python_script

function myFunction() {
  var url = 'WebhookのURL';
  var botMessage = { 'text' : 'Hello from GoogleAppsScript!'}

  var options = {
    'method': 'POST',
    'headers' : {
      'Content-Type': 'application/json; charset=UTF-8'
    },
    'payload':JSON.stringify(botMessage)
  };

  var result = UrlFetchApp.fetch(url, options);
  Logger.log(result);
}

あとは実行するだけでwebhookを設定したチャットルームに投稿されます。
chat3.png

ちなみにwebhookはURLを知っていればG Suiteドメイン外からでも投稿できるので注意。

リファレンス

https://developers.google.com/hangouts/chat/how-tos/webhooks
https://developers.google.com/hangouts/chat/quickstart/incoming-bot-python

43
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
43
Help us understand the problem. What is going on with this article?