Hosting a custom skill to Alexa by implementing a web service

巧了我就是萌 提交于 2019-12-21 02:51:38

问题


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.


回答1:


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!




回答2:


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!



来源:https://stackoverflow.com/questions/39641640/hosting-a-custom-skill-to-alexa-by-implementing-a-web-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!