Exemple #1
0
func jeopardyStart(echoReq *alexa.EchoRequest, session *JeopardySession) (*alexa.EchoResponse, *JeopardySession) {
	catNames := []string{}
	for k, _ := range JeopardyCategories {
		catNames = append(catNames, k)
	}

	msg := ""
	if echoReq.GetIntentName() == "StartJeopardy" {
		msg = JeopardyGreetings[rand.Intn(len(JeopardyGreetings))] + " Please pick one of the following categories: "
	} else {
		msg = "The categories are "
	}
	msg += strings.Join(catNames, ", ")
	echoResp := alexa.NewEchoResponse().OutputSpeech(msg).EndSession(false)

	return echoResp, session
}
Exemple #2
0
func EchoIntentHandler(req *alexa.EchoRequest, res *alexa.EchoResponse) {
	mongo, db := MongoConnect()
	defer mongo.Close()

	session := GetSession(db, req.GetSessionID())

	user, err := UserIndex.getUserByAmazonID(req.GetUserID())
	if err != nil {
		res.OutputSpeech("Sorry, we don't have an account setup for this user.").EndSession(true)
		return
	}

	switch req.GetIntentName() {
	case "SelectBox":
		target, _ := req.GetSlotValue("target")
		if target == "" {
			res.OutputSpeech("I didn't get that. Can you tell me the computer you want again?").EndSession(false)
			return
		}

		if !user.clientExists(target) {
			res.OutputSpeech("The computer you requested isn't online.").EndSession(true)
			return
		}

		session.Target = target
		session.Update(db)

		runCommand(session, user, res)
	case "RunCommand":
		cmd, err := req.GetSlotValue("cmd")
		if err != nil {
			res.OutputSpeech("I'm sorry, but what should I tell " + session.Target + "to do?").EndSession(false)
			return
		}

		session.Cmd = cmd

		payload, _ := req.GetSlotValue("payload")
		session.Payload = payload
		session.Update(db)

		runCommand(session, user, res)
	case "ListCommand":
		names := []string{}
		for _, client := range user.Clients {
			if client.isActive() {
				names = append(names, client.Name)
			}
		}

		if len(names) == 0 {
			res.OutputSpeech("You have no available computes.").EndSession(true)
		} else if len(names) < 2 {
			res.OutputSpeech("You have one available computer. It's name is " + names[0]).EndSession(true)
		} else {
			res.OutputSpeech("You have %d available computers. They are: " + strings.Join(names, ", ")).EndSession(true)
		}
	case "IdCommand":
		res.OutputSpeechSSML(fmt.Sprintf("<speak>Your user ID is <say-as interpret-as=\"digits\">%d</say-as></speak>", user.ID)).EndSession(true)
	default:
		res.OutputSpeech("I'm sorry, I didn't understand your request.").EndSession(false)
	}
}