Alexa Webhook Integration with NPM

Create a Skill API key

Each Skill needs its own API key for tracking.

Create a Skill to get an API key.

Install Dashbot via NPM

npm install --save dashbot

Include Dashbot

Use the API key created above.

const dashbot = require('dashbot')(<strong>process.env.DASHBOT_API_KEY</strong>).alexa;

Log whenever your webhook is called, and whenever you send a response

app.use(bodyParser.json())
...
app.post('/alexa', (req, res) => {
  <strong>dashbot.logIncoming(req.body);</strong>
  ...
  const responseBody = {
    'version': '1.0',
    'response': {
      'outputSpeech': {
        'type': 'PlainText',
        'text': 'Hello World!'
      },
      'card': {
        'content': 'Hello World!',
        'title': 'Hello World',
        'type': 'Simple'
      },
      'shouldEndSession': true
    },
    'sessionAttributes': {}
  };
  <strong>dashbot.logOutgoing(req.body, responseBody);</strong>
  res.send(responseBody);
}

Example

View a sample.

Sending outbound Intents (optional)

Optionally send outbound Intents to be able to rollup messages based on the response.

Add the Intent to the responseBody

app.use(bodyParser.json())
...
app.post('/alexa', function(req, res) {
  dashbot.logIncoming(req.body);
  ...
  const responseBody = {
    <strong>'intent': {
       'name' : 'WEATHER_RESPONSE'
       'inputs' : [
            {
                'name': 'forecast',
                'value': '68 and sunny',
             }
           ]
         }</strong>,
    'version': '1.0',
    'response': {
      'outputSpeech': {
        'type': 'PlainText',
        'text': 'Hello World!'
      },
      'card': {
        'content': 'Hello World!',
        'title': 'Hello World',
        'type': 'Simple'
      },
      'shouldEndSession': true
    },
    'sessionAttributes': {}
  };
  <strong>dashbot.logOutgoing(req.body, responseBody);</strong>
  res.send(responseBody);
}