概要
Serverless の Typetalk 通知プラグイン serverless-plugin-typetalk を作ったので紹介する記事です。
前提知識
Typetalk って何?という方は こちら
Serverless とは?
The Serverless Framework – Build applications comprised of microservices that run in response to events, auto-scale for you, and only charge you when they run. This lowers the total cost of maintaining your apps, enabling you to build more logic, faster.
マイクロサービスのアプリを構築するためのフレームワークです。AWS だけでなく色々なプラットフォームをサポートしており、コミュニティによるプラグインも多数提供されていてとても便利です。
使い方
1) Typetalk でボットを作成します。
メッセージの投稿を行うので、topic.post にチェックを入れます
項目 | 値 |
---|---|
ID | serverless-typetalk-plugin |
Full Name | serverless-typetalk-plugin |
2) ボットの投稿に必要な値を環境変数に設定します。
$ export TYPETALK_TOKEN={手順1で作成したボットのトークン}
$ export TYPETALK_TOPIC_ID={ボットを作成したトピックのID}
3) serverless.yml を作成します。
サンプルコード
// handler.hello
'use strict';
module.exports.hello = async (event) => {
return {
statusCode: 200,
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
}, null, 2),
};
};
# serverless.yml
service: serverless-plugin-typetalk-example
plugins:
- serverless-plugin-typetalk
custom:
typetalk:
token: ${env:TYPETALK_TOKEN}
topicId: ${env:TYPETALK_TOPIC_ID}
provider:
name: aws
runtime: nodejs10.x
functions:
hello:
handler: handler.hello
4) serverless コマンドをインストールします。
$ npm i -g serverless
5) プラグインをインストールします。
$ npm i serverless-plugin-typetalk
6) 実行します。
$ sls deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Typetalk notification has been sent.
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service serverless-plugin-typetalk-example.zip file to S3 (67.2 KB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
.........
Serverless: Stack update finished...
Service Information
service: serverless-plugin-typetalk-example
stage: dev
region: us-east-1
stack: serverless-plugin-typetalk-example-dev
resources: 5
api keys:
None
endpoints:
None
functions:
hello: serverless-plugin-typetalk-example-dev-hello
layers:
None
Serverless: Typetalk notification has been sent.
7) メッセージが投稿されます。
手順は以上となります。いかがだったでしょうか?フィードバック歓迎です