0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Slackチャンネル内で人気の絵文字ランキングをみたい

Posted at

#1.DockerでGoの開発環境を作ってServerlessでAWS Lambdaにデプロイする  
参考
https://qiita.com/kai_kou/items/fc3eab987d7ed2d6f65b

#2.Slack トークン取得  
参考
https://qiita.com/ykhirao/items/3b19ee6a1458cfb4ba21

#3.SlackのPermission設定とメソッド  
メソッドとPermissionの一覧
https://www.utali.io/entry/2016/10/03/004421

今回設定するPermission

スクリーンショット 2019-01-28 19.36.53.png

SlackAPI確認方法

https://slack.com/api/channels.history?channel=[CHANNEL]&count=1000&token=[SLACK_TOKEN]&query=after%3Ayesterday

#4.goのmain.goを絵文字カウント取得コードにする。

参考

Lambdaで動かせるようにmain メソッドの中を変更する

main.go
func main() {
    lambda.Start(MainProcess)
}
func MainProcess() {
	
	token := os.Getenv("SLACK_TOKEN")
	if token == "" {
		log.Fatal("SLACK_TOKEN environment variable should be set")
	}
        //続く

#5.Lambdaの環境変数に2で作成したSLACK_TOKENを設定する

#6.完成したので実行する

コンテナ内
// ビルド
GOOS=linux go build -o bin/main
// lambdaにデプロイ
serverless deploy
// lambdaで実行
serverless invoke -f hello

Slackの画面
スクリーンショット 2019-01-30 21.49.35.png

  • その他参考

How to build a Serverless API with Go and AWS Lambda  
https://www.alexedwards.net/blog/serverless-api-with-go-and-aws-lambda#creating-and-deploying-an-lambda-function

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?