Documentation

Twitter Integration with NPM

Create a bot API key

Each bot needs its own API key for tracking.

Create a bot 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).twitter;

Whenever your bot sends, or receives data, log to Dashbot

Message Format

You can send the following fields:

  • text – string – (required)
  • userId – string – (required) – should be the SAME userId for both incoming and outgoing messages this is NOT the bot’s user ID
  • intent – object – (optional)
    • name – string
    • inputs – array
      • input – object
        • name – string
        • value – string
  • images – array – (optional)
    • image – object
      • url – string
  • buttons – array – (optional)
    • button – object
      • id – string
      • label – string
      • value – string
  • postback – object (optional)
    • buttonClick – object
      • buttonId – string
  • platformJson – object (optional) – send ALL of your platform-specific JSON here. It will be available for viewing in your transcripts.

Log whenever your webhook is called

const messageForDashbot = {
"text": "Blue Bird",
"userId": "1234858592",
"platformJson": {
"direct_message_events": [
{
"type": "message_create",
"id": "1234858589",
"created_timestamp": "1392078023603",
"message_create": {
"target": {
"recipient_id": "1234858592"
},
"sender_id": "3805104374",
"source_app_id": "268278",
"message_data": {
"text": "Blue Bird",
"entities": {
"hashtags": [],
"symbols": [],
"urls": [],
"user_mentions": []
},
"quick_reply_response": {
"type": "options",
"metadata": "external_id_2"
},
"attachment": {
"type": "media",
"media": {}
}
}
}
}
],
"users": {
"1234858592": {
"id": "1234858592",
"created_timestamp": "1415320482361",
"name": "TwitterDev",
"screen_name": "TwitterDev",
"location": "Internet",
"description": "Developer and Platform Relations @Twitter. We are developer advocates. We can't answer all your questions, but we listen to all of them",
"protected": false,
"verified": true,
"followers_count": 440643,
"friends_count": 1534,
"statuses_count": 2837,
"profile_image_url": "http://pbs.twimg.com/profile_images/530814764687949824/npQQVkq8_normal.png",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/530814764687949824/npQQVkq8_normal.png"
},
"3805104374": {
"id": "3805104374",
"created_timestamp": "1449607341142",
"name": "Furni",
"screen_name": "furni",
"location": "San Francisco, CA",
"description": "Furni is Twitter's example company to showcase new developer features.",
"protected": false,
"verified": false,
"followers_count": 297,
"friends_count": 7,
"statuses_count": 1,
"profile_image_url": "http://pbs.twimg.com/profile_images/653712801219805185/S4LvoO9b_normal.png",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/653712801219805185/S4LvoO9b_normal.png"
}
},
"apps": {
"268278": {
"id": "268278",
"name": "Twitter Web Client",
"url": "http://twitter.com"
}
}
}
};
dashbot.logIncoming(messageForDashbot);

Whenever you send a message, log the response

const messageForDashbot = {
"text": "Just a normal text DM out.",
"userId": "1234858592",
"platformJson": {
"direct_message_events": [
{
"type": "message_create",
"id": "1244858585",
"created_timestamp": "1492078023507",
"message_create": {
"target": {
"recipient_id": "3805104374"
},
"sender_id": "1234858592",
"source_app_id": "8829219",
"message_data": {
"text": "Just a normal text DM out.",
"entities": {
"hashtags": [],
"symbols": [],
"urls": [],
"user_mentions": []
},
"attachment": {
"type": "media",
"media": {}
}
}
}
}
],
"users": {
"1234858592": {
"id": "1234858592",
"created_timestamp": "1415320482361",
"name": "TwitterDev",
"screen_name": "TwitterDev",
"location": "Internet",
"description": "Developer and Platform Relations @Twitter. We are developer advocates. We can't answer all your questions, but we listen to all of them",
"protected": false,
"verified": true,
"followers_count": 440643,
"friends_count": 1534,
"statuses_count": 2837,
"profile_image_url": "http://pbs.twimg.com/profile_images/530814764687949824/npQQVkq8_normal.png",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/530814764687949824/npQQVkq8_normal.png"
},
"3805104374": {
"id": "3805104374",
"created_timestamp": "1449607341142",
"name": "Furni",
"screen_name": "furni",
"location": "San Francisco, CA",
"description": "Furni is Twitter's example company to showcase new developer features.",
"protected": false,
"verified": false,
"followers_count": 297,
"friends_count": 7,
"statuses_count": 1,
"profile_image_url": "http://pbs.twimg.com/profile_images/653712801219805185/S4LvoO9b_normal.png",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/653712801219805185/S4LvoO9b_normal.png"
}
},
"apps": {
"8829219": {
"id": "8829219",
"name": "Furni",
"url": "https://twitter.com/furni"
}
}
}
};
dashbot.logOutgoing(messageForDashbot);

Example

View sample code.