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
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Prompt Engineering for Job Search
mfonobong
0
450
We Have a Design System, Now What?
morganepeng
55
8.3k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
520
A Soul's Torment
seathinner
7
3.6k
Everyday Curiosity
cassininazir
0
320
For a Future-Friendly Web
brad_frost
183
10k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Skip the Path - Find Your Career Trail
mkilby
1
230
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
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