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?

holon+GASで動くslack用GPTbot

Posted at

上記で公開済みのholon+GASで動くslack用GPTbotです

  • GAS
  • SLACKワークスペース
  • Openai APIキー

があれば動作します

確かこちらの記事を参考にさせてもらいました

Openai

https://platform.openai.com/settings/organization/api-keys
APIキーを作成します

GAS

https://script.google.com/home
から新規プロジェクトを作成して、レポジトリから

  • main.gs
  • utility.gs
  • universalMessage.gs
  • functionMessage.gs

を配備します

スクリーンショット 2025-03-16 011223.png

ライブラリ

スクリーンショット 2025-03-16 011422.png

下記ライブラリを追加します
"libraryId":

  • 1on93YOYfSmV92R5q59NpKmsyWIQD8qnoLYk-gkQBI92C58SPyA2x1-bq
  • 1O20VxEbcHIYIrrpe_HeqkiaAXNEjIKcTKe3rLl2r_1KJ6GQ_Ib-xkGJG

デプロイ

この状態で一度デプロイします

スクリーンショット 2025-03-16 013043.png

新しいデプロイ

スクリーンショット 2025-03-16 013515.png

実行すると
https://script.google.com/macros/…
形式でウェブアプリURLが発行されるので、メモしておきます

SLACK

https://api.slack.com/apps/
からcreate new app → from scratch でアプリを作成します

名前と使用するワークスペースを選択します
スクリーンショット 2025-03-16 012032.png

app manifest

スクリーンショット 2025-03-16 012519.png

アプリを作成後、app manifest画面で、以下のjsonを入力し、saveします
equest_url にはGASデプロイ時に発行されたウェブアプリURLを設定します

{
  "display_information": {
    "name": "holon2",
    "description": "holon2",
    "background_color": "#000000"
  },
  "features": {
    "bot_user": {
      "display_name": "holon 2",
      "always_online": true
    }
  },
  "oauth_config": {
    "scopes": {
      "bot": [
        "app_mentions:read",
        "channels:history",
        "channels:join",
        "channels:manage",
        "channels:read",
        "chat:write",
        "commands",
        "emoji:read",
        "files:read",
        "files:write",
        "groups:history",
        "groups:read",
        "groups:write",
        "im:history",
        "im:read",
        "im:write",
        "mpim:history",
        "mpim:read",
        "mpim:write",
        "reactions:read",
        "reactions:write",
        "users:read"
      ]
    }
  },
  "settings": {
    "event_subscriptions": {
      "request_url": "https://script.google.com/macros/s/...",
      "bot_events": [
        "app_mention",
        "channel_created",
        "emoji_changed",
        "message.channels",
        "message.groups",
        "message.im"
      ]
    },
    "org_deploy_enabled": false,
    "socket_mode_enabled": false,
    "token_rotation_enabled": false
  }
}

ワークスペースへのインストール

スクリーンショット 2025-03-16 014131.png

install app画面で、アプリのワークスペースへのインストールを実行します
インストールすると、Slack Bot User OAuth トークンが発行されます

GAS - スクリプトプロパティ

スクリーンショット 2025-03-16 011807.png

GASでスクリプトプロパティを設定します

  • OPENAI_KEY : OpenAI APIキー
  • MAX_TOKENS : OpenAI APIへ投げるときの max_completion_tokens (例:100000)
  • MODEL : OpenAIのモデル指定 (例: o1)
  • SLACK_TOKEN : Slack Bot User OAuth トークン
  • APP_ID : Slack App ID (slack appのbasic informationで表示される)
  • BOT_DM_CHANNEL_ID & BOT_USER_ID
    slack上で、アプリの詳細を選択すると見れる
    スクリーンショット 2025-03-16 015422.png
  • REACTION_NAME : Botが処理中につける絵文字名 (例:grey_question)

BOTの動作

スクリーンショット 2025-03-16 020458.png

チャンネルに追加後、メンションを使ってスレッドを開始すると、そのスレッド内で応答します。
一度スレッドで応答した後は、メンションなしでもスレッド上の返信に自動で応答します。
自分以外のメンションを含むリクエストには応答しません。

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?