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
Transcript
13 slides
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
More Decks by mako_makok
See All by mako_makok
Kotlinにおける型の世界と エラーハンドリング / Type World and Error Handling in Kotlin
makomakok
3
1.3k
Javaでも使えるKotlin OSSを目指すためのkotlin.jvmの利用とインターフェース設計/Use of kotlin.jvm and interface design for Kotlin OSS that can also be used in Java
makomakok
0
1k
退屈なことはバッチにやらせよう
makomakok
1
670
Firebase + BoltではじめるSlackアプリ開発
makomakok
0
15k
Featured
See All Featured
A designer walks into a library…
pauljervisheath
211
25k
For a Future-Friendly Web
brad_frost
184
11k
From π to Pie charts
rasagy
1
460
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.9k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
370
Amusing Abliteration
ianozsvald
1
400
Automating Front-end Workflow
addyosmani
1370
210k
Designing Experiences People Love
moore
143
24k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.9k
It's Worth the Effort
3n
188
30k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.7k
So, you think you're a good person
axbom
PRO
2
2.3k