{"id":16696915,"url":"https://github.com/seratch/kenall-for-slack","last_synced_at":"2025-04-10T02:52:33.801Z","repository":{"id":139894146,"uuid":"338993298","full_name":"seratch/kenall-for-slack","owner":"seratch","description":"ケンオール API (kenall.jp) を Slack から使えるようにするアプリ","archived":false,"fork":false,"pushed_at":"2021-02-19T06:56:07.000Z","size":34,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-24T04:22:33.823Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://kenall.jp/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seratch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-15T07:04:16.000Z","updated_at":"2024-01-14T00:02:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"4646f28e-5272-4034-b689-6791d39e93ff","html_url":"https://github.com/seratch/kenall-for-slack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seratch%2Fkenall-for-slack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seratch%2Fkenall-for-slack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seratch%2Fkenall-for-slack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seratch%2Fkenall-for-slack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seratch","download_url":"https://codeload.github.com/seratch/kenall-for-slack/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248147130,"owners_count":21055482,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T17:45:16.366Z","updated_at":"2025-04-10T02:52:33.781Z","avatar_url":"https://github.com/seratch.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## ケンオール API を Slack から使えるようにするアプリ（非公式）\n\nこの Slack アプリは、[ケンオール API](https://kenall.jp/) を Slack から呼び出せるようにする実装例を示すためのサンプルアプリです。\n\n### デモ\n\n\u003cimg src=\"https://user-images.githubusercontent.com/19658/107915466-e230c280-6fa7-11eb-987e-0f1e2a2241c1.gif\" width=500\u003e\n\n### とりあえず動かしてみる\n\nケンオールの API キーを発行、Slack アプリの設定を https://api.slack.com/apps で行った後、以下で起動できます。\n\n#### Slack アプリ初期設定\n\nSlack アプリの設定でやることは\n\n* **Features** \u003e **OAuth \u0026 Permissions** で Bot Token Scopes に `commands` scope を追加\n* **Settings** \u003e **Basic Information** の **Signing Secret** を `SLACK_SIGNING_SECRET` として環境変数に設定\n* **Settings** \u003e **Install App** からインストールし、`xoxb-` ではじまる **Bot User OAuth Access Token** を `SLACK_BOT_TOKEN` として環境変数に設定\n\nが最低限の設定です。後ほどスラッシュコマンド、ショートカット・モーダルの有効化をしましょう。\n\n#### ケンオール設定\n\nアカウントを作成して、トライアルの状態で API キーを取得するだけです。\n\n#### Flask やソケットモードを使ったアプリ設定\n\nこの例は Flask を使っていますが、すでに[ソケットモード](https://api.slack.com/socket-mode)についてご存知なら、そちらの方が楽だと思います。ソケットモードで起動する場合は、[こちらの記事](https://qiita.com/seratch/items/1a460c08c3e245b56441)の Python の例を参考に `python socket_mode_app.py` で起動してみてください。\n\n```bash\ngit clone git@github.com:seratch/kenall-for-slack.git\ncd kenall-for-slack\n\npython3 -m venv .venv\nsource .venv/bin/activate\npip install -U pip\npip install -r requirements.txt\n\nexport SLACK_SIGNING_SECRET=\nexport SLACK_BOT_TOKEN=\nexport KENALL_API_KEY=\n\nFLASK_APP=flask_app.py FLASK_ENV=development flask run -p 3000\n```\n\n別のターミナルで `ngrok http 3000` とすると公開 URL を発行できます。https://api.slack.com/apps のアプリ設定で Request URL に `http://{あなたのサブドメイン}.ngrok.io/slack/events` を設定してください。\n\n#### スラッシュコマンド、ショートカット・モーダルを有効化\n\nFlask で動かしているなら、確定したエンドポイントの URL を Request URL として **Slash Commands** と **Interactivity \u0026 Shortcuts** の設定画面に設定してください。ソケットモードを使っているなら URL の設定は不要です。\n\n\u003cimg width=\"600\"  src=\"https://user-images.githubusercontent.com/19658/107947337-998ffe00-6fd5-11eb-8858-a1527561ec80.png\"\u003e\n\u003cimg width=\"600\" src=\"https://user-images.githubusercontent.com/19658/107947347-9bf25800-6fd5-11eb-98d2-7e6cbe0cbc1e.png\"\u003e\n\nスラッシュコマンドは `/kenall`、グローバルショートカットの Callback ID は `kenall-search` とすると、このサンプルアプリのコードそのままで動作するでしょう。\n\n### Heroku で動かす\n\n[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)\n\nまたは\n\n```bash\nheroku create\nheroku config:set SLACK_SIGNING_SECRET=$SLACK_SIGNING_SECRET\nheroku config:set SLACK_BOT_TOKEN=$SLACK_BOT_TOKEN\nheroku config:set KENALL_API_KEY=$KENALL_API_KEY\n\ngit add . -v\ngit commit -m'ケンオールでKEN_ALLに革命を。'\ngit push heroku main\n```\n\nHeroku アプリが起動したら https://api.slack.com/apps のアプリ設定へ行き、**Interactivity \u0026 Shortcuts** と **Slash Commands** の **Request URL** に `https://{あなたのサブドメイン}.herokuapp.com/slack/events` を設定してください。\n\n### Docker で動かす\n\nFlask + Gunicorn の雛形の Dockerfile を置いてありますが、自由に変更してください。\n\n```bash\ndocker build . -t your-repo/kenall-for-slack\n\ndocker run \\\n  -e SLACK_SIGNING_SECRET=$SLACK_SIGNING_SECRET \\\n  -e SLACK_BOT_TOKEN=$SLACK_BOT_TOKEN \\\n  -e KENALL_API_KEY=$KENALL_API_KEY \\\n  -e PORT=3000 \\\n  -p 3000:3000 \\\n  -it your-repo/kenall-for-slack\n```\n\n### AWS Lambda で動かす\n\n以下は python-lambda で Lambda を作って API Gateway は管理コンソールや aws-cli から手動で作る手順です。\n\n```bash\n# Lambda から Lambda を起動できる権限が必要です\n\nexport policy_arn=`aws iam create-policy --policy-name aws-lambda-invocation-policy --policy-document '{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [\n    {\n      \"Effect\": \"Allow\",\n      \"Action\": [\"lambda:InvokeFunction\", \"lambda:GetFunction\"],\n      \"Resource\": \"*\"\n    },\n    {\n      \"Effect\": \"Allow\",\n      \"Action\": [\n        \"logs:CreateLogGroup\",\n        \"logs:CreateLogStream\",\n        \"logs:PutLogEvents\"\n      ],\n      \"Resource\": \"arn:aws:logs:*:*:*\"\n    }\n  ]\n}' | jq .Policy.Arn | tr -d \\\"`\n\naws iam create-role --role-name aws-lambda-invocation-role --assume-role-policy-document '{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [\n    {\n      \"Effect\": \"Allow\",\n      \"Principal\": { \"Service\": [\"lambda.amazonaws.com\"] },\n      \"Action\": [\"sts:AssumeRole\"]\n    }\n  ]\n}\n'\naws iam attach-role-policy --role-name aws-lambda-invocation-role --policy-arn $policy_arn\n\n# 必要な環境変数をあらかじめ設定しておきます\n\nexport SLACK_SIGNING_SECRET=\nexport SLACK_BOT_TOKEN=\nexport KENALL_API_KEY=\n# Lambda のときはこれを忘れずに\nexport SLACK_PROCESS_BEFORE_RESPONSE=1\n\n# デプロイに python-lambda というツールを使用します（アプリはこれに依存しません）\n\npip install python-lambda\n\nlambda deploy \\\n  --config-file aws_lambda_config.yaml \\\n  --requirements requirements-aws.txt\n```\n\npython-lambda は非常に高速なデプロイができるツールなので、紹介していますが、API Gateway も含め一元管理したい場合は他のソリューションを使ってください。\n\n### ライセンス\n\nThe MIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseratch%2Fkenall-for-slack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseratch%2Fkenall-for-slack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseratch%2Fkenall-for-slack/lists"}