Giter Site home page Giter Site logo

chatty's Introduction

Chatty

Google Apps Scriptでの処理に切り替えました

Chatty-for-GAS


Slackのチャンネルに入っているユーザーにランダムで質問していくBotアプリ
collaを参考に作りました。

動作環境

  • node v16.0.0

Slack Appの登録から使用するまでの流れ

一部操作がMacのクライアントアプリ(バージョン4.23.0)をもとにしているので、今後のSlackのバージョンアップや環境によっては表現や手続きに違いが出てくると思います

文章化したので長くなりましたが10分から15分程度で終わる想定です。

  • 最初にプロジェクトをクローンしてコード内の.env.sampleから.envをコピーで生成する
  • Slack Appでアプリ作成(Create New App)する
    • 作成時に From an app manifest (BETA) を選択しておくとyml貼るだけで権限登録の手続き減るのでおすすめです
  • SLACK_BOT_TOKEN(xoxbで始まるトークン)を取得
    • サイドメニュー -> OAuth & Permissions -> OAuth Tokens for Your Workspace -> Install to Workspaceで作成できます
    • 取得できたら.envのSLACK_BOT_TOKENの値にします
  • Botのスコープや各種設定を加える
    • サイドメニューからBasic Information -> Edit Manifest を選択してこのyml(アプリ名は変更してください)を貼り付けます
    • ymlにはBot Scopeの付与とSubscriptionのEvent追加、Socketモードが有効になるように記述されています
  • SLACK_SIGNING_SECRETを取得
    • Basic Information -> App Credentials -> Signing Secretから取得できます
    • 取得できたら.envのSLACK_SIGNING_SECRETの値にします
  • SLACK_APP_TOKENを取得
    • Basic Information -> App-Level Tokens -> Generate an app-level token でTokenを取得します
    • トークン名はなんでも大丈夫ですが、Scopeはconnections:writeを選択してください
    • 取得できたら.envのSLACK_APP_TOKENの値にします
  • チャンネルにアプリを追加
    • 3の手続きでワークスペースには追加されていると思うのでチャンネルにアプリを追加していきます
    • チャンネルのメニューのOpen channel detailsから詳細を開きます
    • Integrations -> Apps -> Add appsからアプリを追加します
  • POST_CHANNEL_IDを取得
    • アプリを追加したワークスペースを開き、Botを追加するチャンネル選択します
    • チャンネルのメニューのcopy linkからチャンネルのリンクを取得します
    • 末尾のC0から始まる文字列がチャンネルIDになります
    • 取得できたら.envのPOST_CHANNEL_IDの値にします
  • BOT_IDを取得
    • Slack上のAppsから追加したアプリを選択し、メニューのOpen channel detailsから詳細を開きます
    • 詳細に記載されているMember IDがBOT_IDになります
    • 取得できたら.envのBOT_IDの値にします
  • ローカル環境でプロジェクトの動作確認
    • npm install でnode_modulesを追加
    • npm start で起動
    • curl localhost:3000/slack/pickup をリクエストするとチャンネル参加者にランダムで質問(DM)が飛んできます

Slack App Manifest

Botの権限とかはymlで分かるので参考までに貼っておきます。 name, display_nameは各々の環境で変更してください。

重要なポイントはScopeとSubscriptionのEvent、Socketモードが有効になっているところです

_metadata:
  major_version: 1
  minor_version: 1
display_information:
  name: {ここは作成したアプリ名}
features:
  bot_user:
    display_name: {ここは作成したアプリ名}
    always_online: false
oauth_config:
  scopes:
    bot:
      - chat:write
      - im:history
      - im:read
      - im:write
      - mpim:read
      - mpim:write
      - channels:history
      - channels:read
      - groups:history
      - groups:read
      - groups:write
settings:
  event_subscriptions:
    bot_events:
      - message.channels
      - message.groups
      - message.im
  interactivity:
    is_enabled: true
  org_deploy_enabled: false
  socket_mode_enabled: true
  token_rotation_enabled: false

質問一覧

questions.tsに集約しています。
これはテスト用に個人で思いつく範囲で書き出したものなので微妙な質問も入ってます。

chatty's People

Contributors

mittsu333 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.