Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Slack_API_Wrapper_BoltでBotを爆速開発.pdf
Search
mako_makok
May 02, 2021
380
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Slack_API_Wrapper_BoltでBotを爆速開発.pdf
mako_makok
May 02, 2021
More Decks by mako_makok
See All by mako_makok
Kotlinにおける型の世界と エラーハンドリング / Type World and Error Handling in Kotlin
makomakok
3
1.2k
Javaでも使えるKotlin OSSを目指すためのkotlin.jvmの利用とインターフェース設計/Use of kotlin.jvm and interface design for Kotlin OSS that can also be used in Java
makomakok
0
980
退屈なことはバッチにやらせよう
makomakok
1
670
Firebase + BoltではじめるSlackアプリ開発
makomakok
0
15k
Featured
See All Featured
Between Models and Reality
mayunak
4
450
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
A Tale of Four Properties
chriscoyier
163
24k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Making the Leap to Tech Lead
cromwellryan
135
10k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
350
KATA
mclloyd
PRO
35
15k
What does AI have to do with Human Rights?
axbom
PRO
1
2.4k
Believing is Seeing
oripsolob
1
220
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
880
Ethics towards AI in product and experience design
skipperchong
2
370
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Transcript
Slack API Wrapper BoltでBotを爆速開発 @mako_makok 2021/04/28 第二回 Web API LT会
自己紹介 • 名前: 小林允(@mako_makok) • 所属: 株式会社ラクス • 楽楽勤怠のバックエンドエンジニア •
たまにフロントエンドもやる • Spring Boot/Java/Kotlin/TypeScript/React
None
使ったもの • Cloud Functions(Firebase) • Firebase Firestore • Bolt For
JavaScript
Bolt For JavaScript • Slackアプリ構築用のフレームワーク • Slack API Team謹製 •
Slack API Client + Receiver + 便利な型定義 • TypeScriptで書かれている • For JavaScriptだけでなく他の言語でもSDKが提供されている ◦ Python, Java
Initialize トークンを発行してAppに放り込む import { App } from '@slack/bolt' const app
= new App({ token: process.env.SLACK_BOT_TOKEN, signingSecret: process.env.SLACK_SIGNING_SECRET, })
Slack API Client • 第2引数のリスナーがclientを持っている • new Appしたときの認証情報がそのまま利用される app.event('team_join' ,
async ({ event, client }) => { try { await client.chat.postMessage ({ channel: 'foo', text: `いらっしゃい、 <@${event.user.id}>! 🎉`, }) } catch (error) { console.error(error) } })
Slack API Client • Slack APIはAPIが頻繁に更新、機能追加される • たまに破壊的な変更も入る • Slack
APIチームがメンテしているので、変更に追従してくれる • TypeScriptで書かれているので型安全にAPIのパラメータを書くことがで きる
Slack API Client • 便利なユーティリティ ◦ ack() ◦ respond() ▪
Slackからのリクエストに対して同期、非同期でレスポンスを返 す ◦ say() ▪ postMessageの簡略版 say(`いらっしゃい、<@${event.user.id}>! 🎉`)
Slash Command(http) slash command request response Slackアプリ Slackのサーバ 自前のサーバ ※3秒以内にレス
ポンスを返す必 要あり
Boltで実装した場合 import { App, ExpressReceiver } from '@slack/bolt' import {
config } from './functions.setting' export const expressReceiver = new ExpressReceiver ({ signingSecret: config.slack.secret, endpoints: '/events' }) export const app = new App({ receiver: expressReceiver , token: config.slack.token, processBeforeResponse: true, }) レシーバーの設定 endpointsの内容がそのまま ルーティングされる
Boltで実装した場合 export const register = (app: App) => { app.command('/register-word',
async ({ ack, body, context, command }) => { await ack() await app.client.views.open({ token: context.botToken, trigger_id: body.trigger_id , view: { type: 'modal', callback_id: VIEW_ID, ... }) app.view(VIEW_ID, async ({ ack, view, context, body }) => { await ack() ... }) } App.commandでイベントを 定義 App.viewはview上の実装 基本的にformの操作など
まとめ • Slack API wrapper + slash command開発用のMWの提供 • APIクライアントとして使うだけでも便利だし、ガッツリslash
command開 発するにはもってこい • 今Slackアプリ開発するならほぼこれ一択 FirebaseでBoltを動かすサンプル👉 https://github.com/mako-makok/connpass-notificator