Here is the flow we are trying to achieve:

Input > Understanding > Response
(Alexa) > (FB Wit.Ai) > (Alexa)

We wanted the "input" tech to be independant of the "understanding" tech (aka AI), such that we could engage with our chatbot through Amazon's Alexa, a FB messenger chat response, or even text in a web page.

We chose Recime, a 3rd-party open source service for building chatbots.

We also chose to use Facebook's Wit.ai for the heavy lifting of interpreting chats. For Recime and Alxa, we only needed some basic (read: low-code) copy-and-pasting of JavaScript.

When you spin up a new Recime project, it will provide you with a template project folder with code files createed. We recommend the Typescript version of the code as it is simpler and more readable than the ES5/ES6 Javascript version of the same code.

The Recime middleware code that you want to change is in the "Main.ts" file.

  /// <reference path="node.d.ts" />
  import util = require('util');
  import request = require('request');
  
  const {
    Wit,
    log
  } = require('node-wit');

  const MY_TOKEN = 'YOUR-FB-WI.AI-API-TOKEN-GOES-HERE';
  
  const client = new Wit({
    accessToken: MY_TOKEN
  });

  export class Bot {
    private args: any;
    constructor(args: Object) {
      this.args = args;
    }
    get extract() {
      return "message.text";
    }
    execute(cb: any) {
      let args = this.args;
      client.converse(args.chatId, args.question, {}).then((data) => {
          "answer": data.msg
        });
        console.log('Got Wit.ai response: ' + JSON.stringify(data));
      }).catch(console.error);
    }
  }

To run the code on your Mac enter the terminal, navigate to the folder and use npm start.

This modification to the Recime base code allows you to use this Recime service as a simple conduit between the Input and the Response that you get returned from Facebook's wit.ai service.

Amazon Alexa Chatbot Code - the key bit to change is the intent handling:

/**
 * Sets the message in the session and prepares the speech to reply to the user.
 */
function setMessageInSession(intent, session, callback) {
    const cardTitle = intent.name;
    const messageToSendSlot = intent.slots.Message;
    let repromptText = '';
    let sessionAttributes = {};
    const shouldEndSession = false;
    let speechOutput = '';

    if (messageToSendSlot) {
        const messageToSend = messageToSendSlot.value;
        sessionAttributes = createMessageAttributes(messageToSend);
        // speechOutput = `Your message is ${messageToSend}. Send message by saying confirm`;
        speechOutput = `To send ${messageToSend}, say confirm.`;
        repromptText = `Confirm sending ${messageToSend}`;
    } else {
        speechOutput = "I'm not sure what your message is. Please try again.";
        repromptText = "I'm not sure what your message is. You can tell me your " +
            'message by saying, my message is.';
    }

    callback(sessionAttributes,
         buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));
}

The annoying thing I guess is that the Alexa input needs to start with a recognized command "Alexa, Send Message to {Name}" -> then you tell Alexa what the conversation message is. This is required to easily setup Alexa in the code without too much effort.

In the end -> Using FB's wit.ai learning system, Alexa or any other input device we can build a chatbot very quickly that can do stuff.

To make it more complex or to allow it to be able to do more complicated things, you need to train the AI bot with more data, intents and stories.

The great news is this requires no additional coding -> just needs you to start building out the AI understanding more.