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
Azure Functionsを使ってSlackに通知をしてみよう
Search
Shintaro Kanno
July 06, 2022
Programming
0
500
Azure Functionsを使ってSlackに通知をしてみよう
7/6(水) 「Serverless LT初心者向け LT大会 #23 + 楽しいチーム開発の施策とは?」発表資料
Shintaro Kanno
July 06, 2022
Tweet
Share
More Decks by Shintaro Kanno
See All by Shintaro Kanno
アトミックデザイン入門
shintaro8
0
280
gRPCミドルウェアを作ってみよう
shintaro8
1
540
Goの並行処理に入門しよう
shintaro8
0
140
Other Decks in Programming
See All in Programming
初学者でも今すぐできる、Claude Codeの生産性を10倍上げるTips
s4yuba
16
10k
A2A プロトコルを試してみる
azukiazusa1
2
1.3k
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
360
ソフトウェア品質を数字で捉える技術。事業成長を支えるシステム品質の マネジメント
takuya542
1
11k
0626 Findy Product Manager LT Night_高田スライド_speaker deck用
mana_takada
0
150
C++20 射影変換
faithandbrave
0
570
「Cursor/Devin全社導入の理想と現実」のその後
saitoryc
0
770
Goで作る、開発・CI環境
sin392
0
210
“いい感じ“な定量評価を求めて - Four Keysとアウトカムの間の探求 -
nealle
1
8.3k
Railsアプリケーションと パフォーマンスチューニング ー 秒間5万リクエストの モバイルオーダーシステムを支える事例 ー Rubyセミナー 大阪
falcon8823
5
1.1k
#kanrk08 / 公開版 PicoRubyとマイコンでの自作トレーニング計測装置を用いたワークアウトの理想と現実
bash0c7
1
690
PHPで始める振る舞い駆動開発(Behaviour-Driven Development)
ohmori_yusuke
2
330
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Visualization
eitanlees
146
16k
Thoughts on Productivity
jonyablonski
69
4.7k
It's Worth the Effort
3n
185
28k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Building an army of robots
kneath
306
45k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
46
9.6k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.5k
Adopting Sorbet at Scale
ufuk
77
9.4k
Fireside Chat
paigeccino
37
3.5k
Transcript
Azure Functions を使ってSlack に通知をしてみよう
自己紹介 名前 官野 慎太朗 ( かんの しんたろう) 業務 都内IT 企業にてWeb
系の開発業務に従事。 技術経験 Golang, JavaScript/TypeScript, MySQL, PostgreSQL, docker/kubernetes, etc…
目次 1. Azure Functions とは 2. 今回使用する技術について 3. Slack Webhook
URL の取得 4. Function App の設定 5. ローカル上でのプログラム実装 6. Function App へのデプロイ
Azure Functions とは Azure(Microsoft 社) が提供するサービスの一種。 クラウド上にプログラムを実装することができる。 類似サービス:AWS Lambda, GCP
Cloud Function
今回使用する技術 Azure Functions Core Tools JavaScript Slack Webhook URL Weather
Forecast API (Open-Meteo 社)
Slack Webhook URL の取得 Slack 連携には Incoming Webhook URL の発行が必要
Slack app directory の Custom Integrations > Incoming WebHooks より任意のWorkspace の Webhook URL 発行可能。 Incoming WebHooks よりWeb hook URL を作成 ` ` ` ` ` `
Function App の設定 Azure Portal 上でFunction App を構築 今回の名称は azure-weather
環境変数にSlack Webhook URL を設定 ` `
ローカル上でのプログラム実装 ローカルに空の az-function というディレクトリを作成 az-function 内で func new を実行 runtime
は node 使用する言語は JavaScript template は TimerTrigger Function Name は weather 対話形式で関数を作成 ` ` ` ` ` ` ` ` ` ` ` ` ` `
初期ディレクトリ構成 今回手を加えるのは index.js と function.json ` ` ` ` |-
.vscode |- extention.json |- weather |- function.json ←★ |- index.js ←★ |- readme.md |- .gitignore |- host.json |- local.setting.json |- package-lock.json |- package.json
実装部分 axios と @slack/webhook を使用 func start でローカル実行 ` `
` ` ` ` const axios = require('axios'); const { IncomingWebhook } = require('@slack/webhook'); module.exports = async function (context, myTimer) { // ~~~~~~ 以下実装部分 ~~~~~~ const response = await axios.get('https://api.open-meteo.com/v1/forecast?latitude=35.6785&longitude=139.6823&hourly=te const webhook = new IncomingWebhook(process.env.WEBHOOK) await webhook.send({ text: ` 現在の気温は${response.data.current_weather.temperature} です。`, channel: "#demo", username: "Azure Functions", }) // ~~~~~~ 実装部分ここまで ~~~~~~ };
Function App へのデプロイ function.json を編集 実行間隔を5 分おきに設定 scriptFile を index.js
に指定 package.json をweather に移動 azure-weather に weather ディレクトリをデプロイ 実行コマンド: func azure functionapp publish azure-weather function.json 内部 weaher 内の最終的な構成 ` ` ` ` ` ` ` ` ` ` ` ` { "bindings": [ { "name": "myTimer", "type": "timerTrigger", "direction": "in", "schedule": "0 */5 * * * *" } ], |- weather |- function.json |- index.js |- readme.md |- package.json ← 上の階層から移動
デプロイ後のazure-weather Functions に weather が存在 5 分おきに現在の気温をSlack へ通知 デプロイされたweather Slack
への気温の通知 ` `