-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcustom_commands_skills.go
More file actions
84 lines (68 loc) · 2.02 KB
/
custom_commands_skills.go
File metadata and controls
84 lines (68 loc) · 2.02 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"github.com/hashicorp/terraform/helper/schema"
)
func customCommandsSkills() *schema.Resource {
return &schema.Resource{
Create: customCommandsSkillsCreate,
Read: customCommandsSkillsRead,
Update: customCommandsSkillsUpdate,
Delete: customCommandsSkillsDelete,
Schema: map[string]*schema.Schema{
"location": {
Type: schema.TypeString,
Required: true,
},
"custom_commands_speech_key": {
Type: schema.TypeString,
Required: true,
},
"custom_commands_speech_app_id": {
Type: schema.TypeString,
Required: true,
},
"skills_file_path": {
Type: schema.TypeString,
ForceNew: true,
Required: true,
},
"skills_file_md5": {
Type: schema.TypeString,
ForceNew: true,
Required: true,
},
},
}
}
func customCommandsSkillsCreate(d *schema.ResourceData, m interface{}) error {
log.Printf("[LOG] Starting Custom Commands Skills")
appID := d.Get("custom_commands_speech_app_id").(string)
location := d.Get("location").(string)
basePath := fmt.Sprintf("https://%s.commands.speech.microsoft.com/v1.0/apps/%s/slots/default/languages/en-us/model", location, appID)
skillsFilePath := d.Get("skills_file_path").(string)
fileBytes, errorMessage := ioutil.ReadFile(skillsFilePath)
if errorMessage != nil {
return fmt.Errorf("An error happened with ioutil.ReadFile: %+v", errorMessage)
}
apiKey := d.Get("custom_commands_speech_key").(string)
response, errorMessage := CallWebService(basePath, http.MethodPut, apiKey, 200, fileBytes)
if errorMessage != nil {
return fmt.Errorf("An error happened with CallWebService: %+v", errorMessage)
}
log.Printf("[LOG] Response: %+v", response)
d.SetId(appID)
return nil
}
func customCommandsSkillsRead(d *schema.ResourceData, m interface{}) error {
return nil
}
func customCommandsSkillsUpdate(d *schema.ResourceData, m interface{}) error {
return nil
}
func customCommandsSkillsDelete(d *schema.ResourceData, m interface{}) error {
return nil
}