Hosting a custom skill to Alexa by implementing a web service
Asked Answered
V

2

3

I am working on developing a web service which is used to Handling Requests Sent by Alexa and respond back with specific response in .net framework. The request body sent by Alexa to your service in JSON format like below :

{
  "version": "string",
  "session": {
    "new": true,
    "sessionId": "string",
    "application": {
      "applicationId": "string"
    },
    "attributes": {
      "string": {}
    },
    "user": {
      "userId": "string",
      "accessToken": "string"
    }
  },
  "context": {
    "System": {
      "application": {
        "applicationId": "string"
      },
      "user": {
        "userId": "string",
        "accessToken": "string"
      },
      "device": {
        "supportedInterfaces": {
          "AudioPlayer": {}
        }
      }
    },
    "AudioPlayer": {
      "token": "string",
      "offsetInMilliseconds": 0,
      "playerActivity": "string"
    }
  },
  "request": {}
}

and Response Body Syntax in Json format below:

{
  "version": "string",
  "sessionAttributes": {
    "string": object
  },
  "response": {
    "outputSpeech": {
      "type": "string",
      "text": "string",
      "ssml": "string"
    },
    "card": {
      "type": "string",
      "title": "string",
      "content": "string",
      "text": "string",
      "image": {
        "smallImageUrl": "string",
        "largeImageUrl": "string"
      }
    },
    "reprompt": {
      "outputSpeech": {
        "type": "string",
        "text": "string",
        "ssml": "string"
      }
    },
    "directives": [
      {
        "type": "string",
        "playBehavior": "string",
        "audioItem": {
          "stream": {
            "token": "string",
            "url": "string",
            "offsetInMilliseconds": 0
          }
        }
      }
    ],
    "shouldEndSession": boolean
  }
}

I researched on Amazon Developer Forum Hosting a Custom Skill as a Web Service , Handling Requests Sent by Alexabut i am not able to achieve this thing and one thing i am not using Lambda function i want to make a custom skill and my location is not in North US.

I got the Lib. from github here and used in my web service but not able to sync with this library, anyone here to give me a direction how can i do this or how can i started thanks in advance.

Verdure answered 22/9, 2016 at 14:20 Comment(0)
P
2

I've just published a project that uses the same AlexaSkillsKit.NET package that you mention. The goal is to help everyone create Alexa Custom Skills using .NET + Visual Studio that you can easily deploy to Azure.

https://github.com/tamhinsf/Azure4Alexa

There's a sample skill implementation that you can use as a pattern for your own Custom Skill. It makes use of httpClient and the usual async patterns.

Just download and fire up Visual Studio to get started!

Perreira answered 23/9, 2016 at 0:20 Comment(17)
Hi @Tam, Thanks for the response i have a question can i deployed at own IIS Remote Server instead of Azure, if yes then what file should i need to set as a startup file/page thanks.Verdure
Hey there - I've implemented this project as a Web API, so there's no start page configured as you would have in an MVC project. There's a static page in the project root called "default.htm" if you want to point users at something to intro your custom skill.Perreira
Hi @Tam thanks for the respond back, I have followed your instructions steps at github.com/tamhinsf/Azure4Alexa/blob/master/README.md but got the error : "There was an error calling the remote endpoint, which returned HTTP 405 : Method Not Allowed " any idea why this happened.Verdure
What happens when you go to yourserver/default.htm - does the Azure4Alexa static HTML page load up OK?Perreira
yeah its loaded default.htm but when i am trying to Enter Utterance in Test "is there a good service on the tube " then i got the Response :- "There was an error calling the remote endpoint, which returned HTTP 405 : Method Not Allowed". The endpoint url is : myservername.com/alexa at this moment i really don't know why this happened please help me or share you id where i can tell you the whole process thanks.Verdure
@SanjeevSangral your endpoint should be myservername.com/api/alexa unless you've changed the default project configuration that I created. Could you change this setting in the Amazon/Alexa dashboard and see what happens?Perreira
I made this change but error changed "There was an error calling the remote endpoint, which returned HTTP 404 : Not Found"Verdure
If i change the path myservername.com/api/alexa then i'm not able to launch default.htm page but in myservername.com/alexa am able, so what should i do??Verdure
Can I get you to sign up for Azure for free and deploy the project there? :) Unfortunately, I can't see your IIS configuration, but you shouldn't be setting any sort of startup page as this is a WebAPI project. I think you might have a mapping that's causing /api/alexa to misfire.Perreira
now myservername.com/api/alexa/default.htm works fine, but the response which returned HTTP 405 : Method Not AllowedVerdure
@SanjeevSangral - Could I suggest you start with a clean deployment? Like I said, this is an Web API project and there's no default document. It looks like your IIS config has introduced a mapping that's throwing off the API route/controller. "default.htm" is served off of the root in my original product and the Alexa API endpoint lives at /api/alexa.Perreira
I have follow the following steps :Verdure
1 - download the code from github and extract at particular location. 2- Import the project or you can say that open the sol in visual studio 2015. 3 - Update the value of AppId to be the "Application Id" in Azure4Alexa>Alexa>AlexaConstants.cs. 4 - Build the project and rebuild as well, launch in chrome and default.htm page launched.Verdure
5 - Now deployed the project on the server with required credentials like site name, Server, Username etc and after deployed default.htm page launched. 6 - Copy the url without default.htm and the url looks like alexa.myservername.com/api/alexa enter into the endpoint location in Alexa Skill set.Verdure
7 - Update the Intent Schema and Sample Utterances same the located in the file path: Azure4Alexa -> Alexa -> Registration. 8 - enter the utterance and press the Ask Azure Button.Verdure
9 - get the Json Request and response : - There was an error calling the remote endpoint, which returned HTTP 405 : Method Not Allowed. this is the whole process that i have followed now i am totally stuck at this moment.Verdure
"5 - Now deployed the project on the server with required credentials like site name, Server, Username etc and after deployed default.htm page launched." - What is the URL to default.htm after you deploy?Perreira
S
1

It's been some time that the last answer was written, plus the example which Azure4Alexa sample implements, uses deprecated base classes, for cases where you might want to use the 'context' part of your Alexa request, you would want to implement SpeechletBase, ISpeechWithContext in your final Speechlet class.

To be honest, I know the README.md on AlexaSkillsKit.net is very dense, but if you do give it some time, and go through the AlexaSkillsKit.Sample project, and go through the definitions of the implemented base classes, you will understand the request handling through and through.

Let me also take this opportunity to breakdown how I understand the classes and their structures:

SampleSessionSpeechlet Class - Is just the final class that Logs your request, and implements the ISpecchletWithContext(which mandates the implementation of OnSessionStarted(), OnLaunch(), OnIntent() & OnSessionEnded()) these four functions are basically handlers of all the requests that Alexa can send to your Web Service.

SpecchletBase Class - Basically Wraps around the SpeechletService Class which actually does the all heavy lifting.

SpeechletService Class - You basically call its GetResponseAsync()(which the SpeechletSerive's GetResponse() wraps) which takes the passed Alexa Request, parses it into a cute little dataClass called SpeechletRequestEnvelope, does session management, passes the SpeechletRequestEnvelope to your your implementation of the OnSessionStarted(), OnLaunch(), OnIntent() or OnSessionEnded() methods, gets your returned objects and Returns your Alexa Response as a class called the SpeechletResponseEnvelope

Hope that helps with some quick implementation, but I highly recommend going through the Lib directory and understand how things work. And who knows? Contribute!

Squarerigged answered 3/12, 2018 at 8:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.