-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintentTurnOff.go
More file actions
50 lines (38 loc) · 1.08 KB
/
intentTurnOff.go
File metadata and controls
50 lines (38 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"log"
"regexp"
"github.com/aws/aws-sdk-go/service/iotdataplane"
alexa "github.com/ericdaugherty/alexa-skills-kit-golang"
)
// IntentTurnOff
type IntentTurnOff struct {
IOTClient *iotdataplane.IoTDataPlane
Response *alexa.Response
CardTitle *string
Topic *string
}
// Name return the intent name
func (intent *IntentTurnOff) Name() string {
return "TurnOffIntent"
}
// Do perform the Turn Off intent
func (intent *IntentTurnOff) Do() error {
log.Printf("%s triggered", intent.Name())
speechText := `<speak>Turning off
<phoneme alphabet='ipa' ph='Thiŋler'>Thingler</phoneme> smart plug</speak>`
cleanText := regexp.MustCompile("<[^>]*>").
ReplaceAllString(speechText, "")
publishInput := &iotdataplane.PublishInput{
Topic: intent.Topic,
Payload: []byte("off"),
}
_, err := intent.IOTClient.Publish(publishInput)
if err != nil {
return err
}
intent.Response.SetSimpleCard(*intent.CardTitle, cleanText)
intent.Response.SetOutputSSML(speechText)
log.Printf("Set Output speech, value now: %s", intent.Response.OutputSpeech.Text)
return err
}