I have an Alexa skill and a winform on a windows 10 device. I'm sending a message from the winform to Alexa using the Skill Messaging API. I've got the access token, sent the message and received a 202 status code to say the 'message has been successfully accepted, and will be sent to the skill' so I believe everything on the winform side is okay.
The code for it;
var handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = (requestMessage, certificate, chain, policyErrors) => true;
using (var httpClient = new HttpClient(handler))
{
// Obtain skill messaging token
using (var requestToken = new HttpRequestMessage(new HttpMethod("POST"), "https://api.amazon.com/auth/O2/token"))
{
requestToken.Content = new StringContent("grant_type=client_credentials&scope=alexa:skill_messaging&client_id=amzn1.application-oa2-client.************&client_secret=************");
requestToken.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/x-www-form-urlencoded");
var responseToken = httpClient.SendAsync(requestToken);
Response r = JsonConvert.DeserializeObject<Response>(responseToken.Result.Content.ReadAsStringAsync().Result);
// Send message
using (var requestMessage = new HttpRequestMessage(new HttpMethod("POST"), "https://api.eu.amazonalexa.com/v1/skillmessages/users/" + strUserId))
{
requestMessage.Headers.TryAddWithoutValidation("Authorization", "Bearer " + r.access_token);
requestMessage.Content = new StringContent("{ \"data\" : { \"message\" : \"Hi pickle\" }}");
requestMessage.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
var responseMessage = httpClient.SendAsync(requestMessage);
MessageBox.Show(responseMessage.Result.ToString());
}
}
}
How do I capture the incoming message event on the skill though? Looking at the docs I need to handle an incoming request of type Messaging.MessageReceived? Is that correct?
I tried something like that in the skills FunctionHandler but didn't have any luck.
public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
{
// Initialise response
skillResponse = new SkillResponse
{
Version = "1.0",
Response = new ResponseBody()
};
ssmlResponse = new SsmlOutputSpeech();
if (input.GetRequestType() == typeof(LaunchRequest))
{
LaunchRequestHandler(input, context);
}
else if (input.GetRequestType() == typeof(IntentRequest))
{
IntentRequestHandler(input, context);
}
else if (input.GetRequestType() == typeof(SessionEndedRequest))
{
SessionEndedRequestHandler(input, context);
}
else if(input.GetRequestType().Equals("Messaging.MessageReceived"))
{
ssmlResponse.Ssml = "<speak>" + input.Request.Type + "</speak>";
}
skillResponse.Response.OutputSpeech = ssmlResponse;
return skillResponse;
}
How do I react to the message? Is it permissions I need to set up? Does the incoming message not trigger the functionhandler the same way the echo device does?
Thanks