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
Azure Functionsを使ってSlackに通知をしてみよう
Search
Shintaro Kanno
July 06, 2022
Programming
600
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Azure Functionsを使ってSlackに通知をしてみよう
7/6(水) 「Serverless LT初心者向け LT大会 #23 + 楽しいチーム開発の施策とは?」発表資料
Shintaro Kanno
July 06, 2022
Transcript
12 slides
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
への気温の通知 ` `
More Decks by Shintaro Kanno
See All by Shintaro Kanno
アトミックデザイン入門
shintaro8
0
340
gRPCミドルウェアを作ってみよう
shintaro8
1
660
Goの並行処理に入門しよう
shintaro8
0
160
Other Decks in Programming
See All in Programming
作れるエンジニアから、価値を届けるエンジニアへ
ryunakayama
1
260
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
1
2k
Next.js: The final boss of Web Performance
guaca
0
400
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
100
Goコンパイラを作ってGoをもっと理解する / Build a Go compiler to better understand Go
ikura_hamu
0
130
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
370
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
250
まずはコードより業務と向き合う:テーブル解体のためにPdMを呼んだ話
sakawe_ee
0
210
Web3Dライブラリを作ってVue Custom Rendererの仕組みを理解しよう / lets learn vue custom renderer by making 3d library
drumath2237
1
130
Rails初心者がパスキーを実装してみて大変だったこと
ktombow
0
170
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
3
300
Distance field of Julia set
kinakomoti321
0
320
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
96
14k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.6k
Raft: Consensus for Rubyists
vanstee
143
7.9k
Utilizing Notion as your number one productivity tool
mfonobong
4
640
AI: The stuff that nobody shows you
jnunemaker
PRO
11
1.3k
Product Roadmaps are Hard
iamctodd
55
13k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Everyday Curiosity
cassininazir
0
400
Facilitating Awesome Meetings
lara
57
7.2k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
2
2.1k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
380