public async Task <SkillResponse> HandleIntent(IntentRequest input, Session session, SkillRequest request)
        {
            try
            {
                var user = request.Context.System.User;
                if (user.Permissions == null)
                {
                    String   reminderText = "Please go to the Alexa mobile app to grant reminders permissions.";
                    Reprompt r            = new Reprompt(reminderText);
                    return(ResponseBuilder.TellWithAskForPermissionConsentCard(reminderText, new string[] { "alexa::alerts:reminders:skill:readwrite" }, session));
                }

                var reminder = new Reminder
                {
                    RequestTime      = DateTime.UtcNow,
                    Trigger          = new RelativeTrigger(12 * 60 * 60),
                    AlertInformation = new AlertInformation(new[] { new SpokenContent("It's a test", "en-US") }),
                    PushNotification = PushNotification.Enabled
                };
                var client = new RemindersClient(RemindersClient.ReminderDomain, request.Context.System.ApiAccessToken);
                // var alertList = await client.Get();
                var alertDetail = await client.Create(reminder);

                String   speechText = "You successfully schedule a daily reminder at one p. m. to get an apple";
                Reprompt rp         = new Reprompt(speechText);
                var      response   = ResponseBuilder.Ask(speechText, rp, session);
                return(response);
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.StackTrace);
                return(ResponseBuilder.Ask("Some error occured while creating reminder", null));
            }
        }
        private async Task <SkillResponse> TrySendReminder(Event meetupEvent, DateTime reminderDate, string accessToken)
        {
            var speech = new Speech(
                new Paragraph(
                    new Sentence(
                        new PlainText($"You have a {meetupEvent.Group.Name} meetup happening on "),
                        new SayAs(reminderDate.ToString("f"), InterpretAs.Time)
                        )));

            var reminder = new Reminder
            {
                RequestTime      = DateTime.Now,
                Trigger          = new AbsoluteTrigger(reminderDate),
                PushNotification = PushNotification.Disabled,
                AlertInformation = new AlertInformation(new[]
                {
                    new SpokenContent
                    {
                        Locale = "en-GB",
                        Ssml   = speech.ToXml()
                    }
                })
            };

            var client = new RemindersClient(RemindersClient.ReminderDomain, accessToken);

            try
            {
                await client.Create(reminder);

                return(ResponseBuilder.Tell("Okay, I've created that reminder for you"));
            }
            catch (InvalidOperationException ex)
            {
                var errorBody = ex.Message.Substring(ex.Message.IndexOf("body: ") + 6);
                Console.WriteLine(errorBody);
                var code = JObject.Parse(errorBody).Value <string>("code");

                switch (code)
                {
                case "UNAUTHORIZED":
                case "INVALID_BEARER_TOKEN":
                    return(ResponseBuilder.Tell(
                               "Unfortunately reminder permissions haven't been enabled for this skill. You can give permission by accessing the skill settings in your alexa app"));

                default:
                {
                    Console.WriteLine(ex.ToString());
                    return(ResponseBuilder.Tell(
                               "Sorry, I was unable to create your reminder for an unexpected reason. Please try again"));
                }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(ResponseBuilder.Tell(
                           "Sorry, I was unable to create your reminder for an unexpected reason. Please try again"));
            }
        }
Beispiel #3
0
        public async Task CreateGeneratesExpectedCall()
        {
            var responseBody = Utility.ExampleFileContent("createresponse.json");
            var reminder     = Utility.ExampleFileContent <Reminder>("reminder.json");
            var netClient    = new HttpClient(new ActionMessageHandler(async req =>
            {
                Assert.Equal(HttpMethod.Post, req.Method);
                Assert.Equal("/v1/alerts/reminders", req.RequestUri.PathAndQuery);
                var content = JsonConvert.DeserializeObject <Reminder>(await req.Content.ReadAsStringAsync());
                Assert.IsType <AbsoluteTrigger>(content.Trigger);

                return(new HttpResponseMessage(HttpStatusCode.Created)
                {
                    Content = new StringContent(responseBody)
                });
            }));
            var client   = new RemindersClient(netClient);
            var response = await client.Create(reminder);

            Assert.NotNull(response);
            Assert.IsType <ReminderChangedResponse>(response);
            Assert.Equal("abcdef", response.AlertToken);
        }
Beispiel #4
0
        private static async Task <ReminderChangedResponse> CreateReminderAsync(SkillRequest skillRequest, Reminder reminder)
        {
            var client = new RemindersClient(skillRequest);

            return(await client.Create(reminder));
        }
        public async Task <SkillResponse> handler([FromBody] SkillRequest skillRequest)
        {
            mailme("Starting " + JsonConvert.SerializeObject(skillRequest));
            var requestType = skillRequest.GetRequestType();

            SkillResponse response = null;

            if (requestType == typeof(LaunchRequest))
            {
                response = ResponseBuilder.Tell("Welcome to Testy McTestface. How can we help you?");
                response.Response.ShouldEndSession = false;
                return(response);
            }
            if (requestType == typeof(SessionEndedRequest))
            {
                response = ResponseBuilder.Tell("Goodbye");
                response.Response.ShouldEndSession = true;
                return(response);
            }

            if (requestType == typeof(IntentRequest) || requestType == typeof(BuiltInIntent))
            {
                var intentRequest = skillRequest.Request as IntentRequest;
                if (intentRequest.Intent.Name == "AMAZON.StopIntent")
                {
                    response = ResponseBuilder.Tell("Goodbye");
                    response.Response.ShouldEndSession = true;
                    return(response);
                }
                if (intentRequest.Intent.Name == "AMAZON.CancelIntent")
                {
                    response = ResponseBuilder.Tell("Goodbye");
                    response.Response.ShouldEndSession = true;
                    return(response);
                }
                if (intentRequest.Intent.Name == "AMAZON.NavigateHomeIntent")
                {
                    response = ResponseBuilder.Tell("Goodbye");
                    response.Response.ShouldEndSession = true;
                    return(response);
                }
                if (intentRequest.Intent.Name == "AMAZON.HelpIntent")
                {
                    response = ResponseBuilder.Tell("You can ask me to say something. How may we help you now?");
                    response.Response.ShouldEndSession = false;
                    return(response);
                }

                if (intentRequest.Intent.Name == "IntentTalkToMe")
                {
                    FullAddress fullAddress = null;
                    try
                    {
                        CustomerProfileClient aclient = new CustomerProfileClient(skillRequest);
                        fullAddress = await aclient.FullAddress();
                    }
                    catch
                    {}
                    if (fullAddress == null)
                    {
                        response = ResponseBuilder.Tell("Sorry, but Testy McTestFace needs access to your address, you can allow this in the alexa app or website.");
                        response.Response.ShouldEndSession = true;
                        return(response);
                    }
                    string addr = (fullAddress.AddressLine1 ?? "") + "," + (fullAddress.AddressLine2 ?? "") + "," +
                                  (fullAddress.AddressLine3 ?? "") + "," + (fullAddress.City ?? "");
                    return(ResponseBuilder.Tell("Hi, I'm Testy McTestFace and your address is " + addr));
                }


                if (intentRequest.Intent.Name == "WhatDoesSkyColourMean")
                {
                    string temp = "";
                    if (intentRequest.Intent.Slots != null)
                    {
                        foreach (KeyValuePair <string, Slot> item in intentRequest.Intent.Slots)
                        {
                            try
                            {
                                switch (item.Key)
                                {
                                case "SkyColourSlot": temp = item.Value.Value.ToLower(); break;

                                default: break;
                                }
                            }
                            catch { }
                        }
                    }
                    switch (temp)
                    {
                    case "blue": temp = "It means that refraction of light makes it seem so."; break;

                    case "red": temp = "If night time then shepards are happy allegedly"; break;

                    case "black": temp = "It either means it's night time or your eyes are closed"; break;

                    case "falling": temp = "It means you need to go tell chicken little quickly"; break;

                    default: temp = "I'm at a loss as to what that means."; break;
                    }
                    return(ResponseBuilder.Tell(temp));
                }

                if (intentRequest.Intent.Name == "IntentSetReminder")
                {
                    try
                    {
                        var reminder = new Reminder
                        {
                            RequestTime      = DateTime.UtcNow,
                            Trigger          = new RelativeTrigger(12 * 60 * 60),
                            AlertInformation = new AlertInformation(new[] { new SpokenContent("Testy McTestface reminder", "en-GB") }),
                            PushNotification = PushNotification.Enabled
                        };
                        var rclient     = new RemindersClient(skillRequest);
                        var alertDetail = await rclient.Create(reminder);

                        return(ResponseBuilder.Tell("Reminder has been set"));
                    }
                    catch (Exception e)
                    {
                        // This will normally be that the user has not authorised reminders so you need to tell them how.
                        return(ResponseBuilder.Tell("Error :" + e.Message));
                    }
                }
            }


            return(ResponseBuilder.Tell("Hi, something has went wrong"));
        }