0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GASを使用してGooglechatを送る方法

Last updated at Posted at 2025-02-03

GoogleApplicationScript(GAS)を使用して、Googlechatを送ることができました。
送信先のチャットスペースを作成し、WEBhookURLを取得して、textに投稿したいメッセージを代入すれば、チャットを送信できます。
GoogleChatでWEBhookURLを取得するにはGoogle Workspace(有料)を契約する必要があるため、ご注意ください。

WEBhookURLを取得方法を説明します。
Gmailを開いて、左のバーからchatを選択し、「チャットを新規作成」をクリックします。
チャットを送信したい連絡先を選択し、「スペースを作成」をクリック
チャットスペースの名称を決めて、スペースを作成
スクリーンショット 2025-02-03 171846.png
スクリーンショット 2025-02-03 172522.png
アプリと統合→Webhook をクリック

これで、WebhookのURLを取得することができました。

では。Googleスプレッドシートを開いて、コードを書いていきます。
拡張機能から、AppsScriptを開いてください
chat.png
以下のような画面に遷移しますchat.png

ここに、以下のコードを書き込んで、「実行」をクリックしてください。
取得したWebhookURLを入力するのを忘れないでくださいね!

chat
function chat() {
  const webhookUrl = "ここに取得したWebhookのURLを入力"
  const payload = {
    text: "test"
  };

  const options = {
    method: 'post',
    contentType: 'application/json',
    payload: JSON.stringify(payload)
  };

  try {
    UrlFetchApp.fetch(webhookUrl, options);
  } catch (sendError) {
    Logger.log('チャット通知の送信に失敗しました: ' + sendError.message);
  }
}

以下のような画面が出てくるので「権限を確認」をクリック
chat2.png

普段使用しているアカウントを選択
chat3.png

安全なページに戻りたくなりますが(笑)、「詳細」をクリック
chat4.png

「(安全ではないページ)に移動」とある部分をクリック
chat5.png

「続行」をクリック
chat6.png

これで、作成したチャットスペースに「test」というもんごんを投稿できたと思います。
GoogleChatは個人で使われている方は少ないと思いますので、仕事でGASを使い始めたような方には役に立つ内容になったかと思います!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?