-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
106 lines (92 loc) · 3.29 KB
/
Copy pathmain.go
File metadata and controls
106 lines (92 loc) · 3.29 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"fuji-alexa/internal/app"
alexa2 "fuji-alexa/internal/models/alexa"
"github.com/aws/aws-lambda-go/lambda"
"strconv"
"strings"
)
func HandleFavoriteAlbumIntent(request alexa2.Request) alexa2.Response {
//return alexa.NewSimpleResponse("Frontpage Deals", "Frontpage deal data here")
var builder alexa2.SSMLBuilder
builder.Say("Here are your favorite album:")
builder.Pause("1000")
var album app.Album
album = app.GetAlbum(310730204)
builder.Say(album.ArtistName)
builder.Pause("500")
builder.Say(album.Name)
return alexa2.NewSSMLResponse("Favorite Album", builder.Build())
}
func HandleNumberOfPlaylistsIntent(request alexa2.Request) alexa2.Response {
var builder alexa2.SSMLBuilder
count := app.GetPlaylistCount(request.Session.User.UserID)
builder.Say("You have ")
builder.Say(strconv.Itoa(count))
builder.Say(" playlists in your Apple Music Library")
return alexa2.NewSSMLResponse("Playlist Count", builder.Build())
}
func HandleShuffleIntent(request alexa2.Request) alexa2.Response {
var builder alexa2.SSMLBuilder
playlistName := request.Body.Intent.Slots["playlistName"].Value
playlistID := app.FindPlaylist(request.Session.User.UserID, strings.ToLower(playlistName))
if playlistID == "" {
builder.Say("Apologies. I am unable to to find the playlist " + playlistName)
return alexa2.NewSSMLResponse("Playlist Shuffled", builder.Build())
}
newName, err := app.ShufflePlaylist(request.Session.User.UserID, playlistID, playlistName)
if err != nil {
builder.Say("Apologies. I am unable to shuffle the playlist at this moment.")
return alexa2.NewSSMLResponse("Playlist Shuffled", builder.Build())
}
builder.Say("We have shuffled your playlists into a new playlist called " + newName)
return alexa2.NewSSMLResponse("Playlist Shuffled", builder.Build())
}
func HandleHelpIntent(request alexa2.Request) alexa2.Response {
//return alexa.NewSimpleResponse("Help", "Help regarding the available commands here")
var builder alexa2.SSMLBuilder
builder.Say("Here are some of the things you can ask:")
builder.Pause("1000")
builder.Say("What are my favorite albums.")
builder.Pause("1000")
builder.Say("Shuffle my playlist.")
return alexa2.NewSSMLResponse("Fuji Music Help", builder.Build())
}
func HandleAboutIntent(request alexa2.Request) alexa2.Response {
return alexa2.NewSimpleResponse(
"About",
"Fuji Music is a project created by Christopher Sheridan to enhance the Apple Music in Alexa.")
}
func IntentDispatcher(request alexa2.Request) alexa2.Response {
var response alexa2.Response
switch request.Body.Intent.Name {
case "FavoriteAlbum":
response = HandleFavoriteAlbumIntent(request)
case "PlaylistCount":
response = HandleNumberOfPlaylistsIntent(request)
case "ShufflePlaylist":
response = HandleShuffleIntent(request)
case alexa2.HelpIntent:
response = HandleHelpIntent(request)
case "AboutIntent":
response = HandleAboutIntent(request)
default:
response = HandleAboutIntent(request)
}
return response
}
type FeedResponse struct {
Channel struct {
Item []struct {
Title string `xml:"title"`
Link string `xml:"link"`
} `xml:"item"`
} `xml:"channel"`
}
// Handler represents the Handler of lambda
func Handler(request alexa2.Request) (alexa2.Response, error) {
return IntentDispatcher(request), nil
}
func main() {
lambda.Start(Handler)
}