Hariharan Prabhakar
Published

Mitsuku

Everyone needs someone to talk to.

BeginnerFull instructions provided1 hour1,888
Mitsuku

Things used in this project

Story

Read more

Code

ChatBot

snippets
Upload this file to the Lambda Function in AWS Amazon
No preview (download only).

lambda function

JavaScript
the code in chatbot.zip
// Mitsuku api is used to get the response for your question.
var m = require('mitsuku-api')();
 

exports.handler = (event, context, callback) => {
    try {
    var http = require('http');
    if (event.session.new) {
      // New Session
      console.log("NEW SESSION");
    }

    switch (event.request.type) {
//ON Launch Intent
      case "LaunchRequest":
        // Launch Request
        console.log(`LAUNCH REQUEST`);
        m.send('hello world')
  .then(function(response){
    //The response which is fed to the buildSpeechletResponse is the Response
    // being generated by the Mitsuku Api
    context.succeed(
          generateResponse(
            buildSpeechletResponse(response, false),
            {}
          )
        );
  });

        break;

      case "IntentRequest":
        switch(event.request.intent.name){
            //ON Intent Request, When you ask anything after invoking the Skill
            case "askbot":
                var text;
                console.log("send")
                if(event.request.intent.slots.ques.value){
                    text = event.request.intent.slots.ques.value;
                }
                text = text+'     .';
                // Checks the input for bye and the end the session.
                if(text == 'bye'){
                m.send(text)
  .then(function(response){
    context.succeed(
          generateResponse(
            buildSpeechletResponse(response, true),
            {}
          )
        );
  });
                }else{
                m.send(text)
  .then(function(response){
    context.succeed(
          generateResponse(
            buildSpeechletResponse(response, false),
            {}
          )
        );
  });
                }
                
                    break;
        

            
        }
        // Intent Request
        //console.log(`INTENT REQUEST`)
        //context.succeed(
        //  generateResponse(
        //    buildSpeechletResponse("Hello,"+event.request.intent.slots.username.value, true),
        //    {}
        //  )
        //)
        break;

      case "SessionEndedRequest":
        // Session Ended Request
        console.log(`SESSION ENDED REQUEST`);
        break;

      default:
        context.fail(`INVALID REQUEST TYPE: ${event.request.type}`);

    }

  } catch(error) { context.fail(`Exception: ${error}`) }





}

    


// Helpers Functions
buildSpeechletResponse = (outputText, shouldEndSession) => {

  return {
    outputSpeech: {
      type: "PlainText",
      text: outputText
    },
    shouldEndSession: shouldEndSession
  }

}

generateResponse = (speechlet, sessionAttributes) => {

  return {
    version: "1.0",
    sessionAttributes: sessionAttributes,
    response: speechlet
  }
}

Intent Schema

JSON
Alexa Skill Kit Intent Schema
{
  "intents":[
							{
            "intent": "askbot",
            "slots": [
                {
                    "name": "ques",
                    "type": "AMAZON.LITERAL"
                }
            ]
                }  
  ]
  
}

Sample Utterances

snippets
askbot {what is your name|ques}

README

snippets
Lambda Function:

1.Create the Lambda function , the RunTime is Node.js 4.3
	It uses a node modules(mitsuku-api),so it has to be zipped and uploaded to the aws.amazon
2.Handler:index.handler
3.Role : Choose existing role	
4.Existing role:lambda_basic_execution
5.Check the details and create the Function.

Alexa SKill

1.Set the name of the skill,invocation name for the skill
2.Set the Intent Scheme and the sample utterances
3.Copy paste the ARN of the lambda function that you wrote, In skill configuration menu to the Service Endpoint.
4.Save and test the skill and Start using the skill.

Credits

Hariharan Prabhakar

Hariharan Prabhakar

2 projects • 3 followers
Computer Engineer

Comments