Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Slack_API_Wrapper_BoltでBotを爆速開発.pdf
Search
mako_makok
May 02, 2021
360
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
950
退屈なことはバッチにやらせよう
makomakok
1
650
Firebase + BoltではじめるSlackアプリ開発
makomakok
0
15k
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
The SEO Collaboration Effect
kristinabergwall1
1
480
What's in a price? How to price your products and services
michaelherold
247
13k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
250
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
300
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
160
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
250
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
840
A Tale of Four Properties
chriscoyier
163
24k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
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