Пример #1
0
        public async Task GetMobileNumberGeneratesCorrectRequest()
        {
            const string countryCode  = "+1";
            const string phoneNumber  = "999-999-9999";
            const string fullNamePath = "/v2/accounts/~current/settings/Profile.mobileNumber";
            var          runHandler   = false;
            var          httpClient   = new HttpClient(new ActionMessageHandler(req =>
            {
                runHandler = true;
                Assert.Equal(req.RequestUri.PathAndQuery, fullNamePath);
                return(new HttpResponseMessage(System.Net.HttpStatusCode.OK)
                {
                    Content = new StringContent(Utility.GetExampleJson("MobileNumber.json"))
                });
            }))
            {
                BaseAddress = new Uri("https://testclient.com", UriKind.Absolute)
            };

            var client      = new CustomerProfileClient(httpClient);
            var phoneResult = await client.MobileNumber();

            Assert.True(runHandler);
            Assert.Equal(countryCode, phoneResult.CountryCode);
            Assert.Equal(phoneNumber, phoneResult.PhoneNumber);
        }
        public async Task GetRegionAndPostalCodeThrowsOnNullDevice()
        {
            var client = new CustomerProfileClient(new HttpClient());
            var exc    = await Assert.ThrowsAsync <ArgumentNullException>(() => client.RegionAndPostalCode(null));

            Assert.Equal("deviceId", exc.ParamName);
        }
        public async Task GetRegionAndPostalCode()
        {
            const string countryCode  = "GB";
            const string postcode     = "NG1 1RE";
            const string fullNamePath = "/v1/devices/amzn1.ask.device.deviceid/settings/address/countryAndPostalCode";
            var          runHandler   = false;
            var          httpClient   = new HttpClient(new ActionMessageHandler(req =>
            {
                runHandler = true;
                Assert.Equal(req.RequestUri.PathAndQuery, fullNamePath);
                return(new HttpResponseMessage(System.Net.HttpStatusCode.OK)
                {
                    Content = new StringContent(Utility.GetExampleJson("RegionAndPostalCode.json"))
                });
            }))
            {
                BaseAddress = new Uri("https://testclient.com", UriKind.Absolute)
            };

            var client = new CustomerProfileClient(httpClient);
            var regionAndPostalCode = await client.RegionAndPostalCode("amzn1.ask.device.deviceid");

            Assert.True(runHandler);
            Assert.Equal(countryCode, regionAndPostalCode.CountryCode);
            Assert.Equal(postcode, regionAndPostalCode.PostalCode);
        }
        public async Task GetCustomerAddressThrowsOnNullDevice()
        {
            var client = new CustomerProfileClient(new HttpClient());
            var exc    = await Assert.ThrowsAsync <ArgumentNullException>(() => client.FullAddress(null));

            Assert.Equal("deviceId", exc.ParamName);
        }
Пример #5
0
        public void ClientSetDirectlySetCorrectly()
        {
            var lowClient = new HttpClient();

            var client = new CustomerProfileClient(lowClient);

            Assert.Equal(lowClient, client.Client);
        }
Пример #6
0
        //*************************SMSClient initialization***********************************************************************************************************************************************
        /// <summary>
        /// Initialize SMS client using specified 'configuration' parameter </summary>
        /// <param name="configuration"> - parameter containing OneAPI configuration data </param>
        public SMSClient(Configuration configuration)
        {
            this.configuration = configuration;

            //Initialize Clients
            customerProfileClient = new CustomerProfileClientImpl(configuration, onLogin, onLogout);
            smsMessagingClient = new SMSMessagingClientImpl(configuration);
            hlrClient = new HLRClientImpl(configuration);
            ussdClient = new USSDClientImpl(configuration);
            networksClient = new NetworksClientImpl(configuration);
        }
Пример #7
0
        //*************************SMSClient initialization***********************************************************************************************************************************************
        /// <summary>
        /// Initialize SMS client using specified 'configuration' parameter </summary>
        /// <param name="configuration"> - parameter containing OneAPI configuration data </param>
        public SMSClient(Configuration configuration)
        {
            this.configuration = configuration;

            //Initialize Clients
            customerProfileClient = new CustomerProfileClientImpl(configuration, onLogin, onLogout);
            smsMessagingClient    = new SMSMessagingClientImpl(configuration);
            hlrClient             = new HLRClientImpl(configuration);
            ussdClient            = new USSDClientImpl(configuration);
            networksClient        = new NetworksClientImpl(configuration);
        }
Пример #8
0
        public void CreateFromSkillRequestSetupCorrectly()
        {
            const string endpoint    = "https://testclient/";
            const string accesstoken = "accesstoken";

            var request = new SkillRequest
            {
                Context = new Context
                {
                    System = new AlexaSystem
                    {
                        ApiEndpoint    = endpoint,
                        ApiAccessToken = accesstoken
                    }
                }
            };

            var client = new CustomerProfileClient(request);

            Assert.Equal(endpoint, client.Client.BaseAddress.ToString());
            Assert.Equal(accesstoken, client.Client.DefaultRequestHeaders.Authorization.Parameter);
        }
Пример #9
0
        public async Task GetEmailGeneratesCorrectRequest()
        {
            const string expectedResult = "*****@*****.**";
            const string fullNamePath   = "/v2/accounts/~current/settings/Profile.email";
            var          runHandler     = false;
            var          httpClient     = new HttpClient(new ActionMessageHandler(req =>
            {
                runHandler = true;
                Assert.Equal(req.RequestUri.PathAndQuery, fullNamePath);
                return(new HttpResponseMessage(System.Net.HttpStatusCode.OK)
                {
                    Content = new StringContent(Utility.GetExampleJson("Email.json"))
                });
            }))
            {
                BaseAddress = new Uri("https://testclient.com", UriKind.Absolute)
            };

            var client      = new CustomerProfileClient(httpClient);
            var emailResult = await client.Email();

            Assert.True(runHandler);
            Assert.Equal(expectedResult, emailResult);
        }
Пример #10
0
        public async Task <SkillResponse> handler([FromBody] SkillRequest 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));
                }
            }


            return(ResponseBuilder.Tell("Hi, something has went wrong"));
        }
        public static async Task <FullAddress> AlexaGetUserAddress(this ITurnContext context)
        {
            var profileClient = new CustomerProfileClient(context.GetAlexaRequestBody());

            return(await profileClient.FullAddress());
        }
        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"));
        }