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')(process.env.DASHBOT_API_KEY).alexa;

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

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