Last active
June 7, 2018 00:21
-
-
Save mogeta/933e225947b0af1d746440442f6020f7 to your computer and use it in GitHub Desktop.
AWS IoT エンタープライズボタンを押したら、slackに投稿する。ver 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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