コストをかけないでフィードバックを受け取る機能を実装してみた
内容
- Cloud FunctionsでSlack APIを実行してメッセージを送る
- アプリでフィードバック送信フォームを作る
Slack APIでメッセージを送る
Slack APIの仕様は↓から確認できる
今回はCloud Functions + go言語で作ってみた
Peperomia/send_feedback.go at master · wheatandcat/Peperomia · GitHub
package app import ( "net/http" "os" "strings" "github.com/nlopes/slack" ) func SendFeedback(w http.ResponseWriter, r *http.Request) { message, ok := r.URL.Query()["message"] if !ok { http.Error(w, "not params", http.StatusInternalServerError) return } api := slack.New(os.Getenv("SLACK_API_TOKEN")) attachment := slack.Attachment{ Color: "#36a64f", Text: strings.Join(message, " "), } if _, _, err := api.PostMessage("app-feedback", slack.MsgOptionText("以下のフィードバックをもらいました", false), slack.MsgOptionAttachments(attachment)); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } w.Write([]byte("OK")) }
■.env.yaml
SLACK_API_TOKEN: *****************************
以下のコマンドでデプロイ
functions deploy SendFeedback --runtime go111 --trigger-http --env-vars-file .env.yaml
さっそくcurlで送信できるか確認
curl https://us-central1-single-kayak-229714.cloudfunctions.net/SendFeedback?message=aaaa
こんな感じで表示されます
組み込み
あとはアプリに組み込んで、こんな感じになりました
Peperomia/PeperomiaNative/src/components/pages/Feedback at master · wheatandcat/Peperomia · GitHub