Skip to content

Instantly share code, notes, and snippets.

@mogeta
Last active June 7, 2018 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mogeta/933e225947b0af1d746440442f6020f7 to your computer and use it in GitHub Desktop.
Save mogeta/933e225947b0af1d746440442f6020f7 to your computer and use it in GitHub Desktop.
AWS IoT エンタープライズボタンを押したら、slackに投稿する。ver 1
package main
import (
"fmt"
"github.com/aws/aws-lambda-go/lambda"
"github.com/nlopes/slack"
)
func Post(event IotButtonEvent) (string, error) {
api := slack.New("xxxx-xxxxxxxxx-xxxxxxxxxx")
// send message
params := slack.PostMessageParameters{}
var respChannel, respTimestamp, err = api.PostMessage("XXXXXXXXX", "イラッとしたね!", params)
if err != nil {
fmt.Printf("%s\n", err)
return "error", err
}
// result
fmt.Println(event.DeviceEvent.ButtonClicked.ClickType)
return fmt.Sprintf("%s:%s", respChannel, respTimestamp), nil
}
func main() {
lambda.Start(Post)
}
package main
type IotButtonEvent struct {
DeviceInfo struct {
DeviceID string `json:"deviceId"`
Type string `json:"type"`
RemainingLife float64 `json:"remainingLife"`
Attributes struct {
ProjectName string `json:"projectName"`
ProjectRegion string `json:"projectRegion"`
PlacementName string `json:"placementName"`
DeviceTemplateName string `json:"deviceTemplateName"`
} `json:"attributes"`
} `json:"deviceInfo"`
DeviceEvent struct {
ButtonClicked struct {
ClickType string `json:"clickType"`
ReportedTime int64 `json:"reportedTime"`
} `json:"buttonClicked"`
} `json:"deviceEvent"`
PlacementInfo struct {
ProjectName string `json:"projectName"`
PlacementName string `json:"placementName"`
Attributes struct {
Key1 string `json:"key1"`
} `json:"attributes"`
Devices struct {
LightButton string `json:"lightButton"`
} `json:"devices"`
} `json:"placementInfo"`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment