SMS is a text messaging service component of most communication systems. Analysis of text message content can highlight customer inquiry patterns and response effectiveness.
Welcome to the SMS documentation for Dimension! Integrating Dimension into your SMS chatbot is quick and easy.
If you have any questions, comments, or suggestions, please feel free to contact us.
SMS 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 Dimension via NPM
npm install --save dimensionlabs
Include Dimension
Use the API key created above.
const dimension = require('dimension')(process.env.DIMENSION_API_KEY).sms;
Whenever your bot sends, or receives data, log to Dimension
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
- input – object
- images – array – (optional)
- image – object
- url – string
- image – object
- buttons – array – (optional)
- button – object
- id – string
- label – string
- value – string
- button – object
- postback – object (optional)
- buttonClick – object
- buttonId – string
- buttonClick – object
- 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 messageForDimension= {
"text": "Hi, bot",
"userId": "+14155551234",
"platformJson": {
"whateverJson": "any JSON specific to your platform can be stored here -- if you are using Twilio, put the req.body here"
}
};
dimension.logIncoming(messageForDimension);
Whenever you send a message, log the response
const messageForDimension = {
"text": "Hello, my human pet",
"userId": "+14155551234",
"platformJson": {
"whateverJson": "any JSON specific to your platform can be stored here -- if you are using Twilio, put the req.body here"
}
};
dimension.logOutgoing(messageForDimension);
Example
View sample code for complete example.
SMS Integration with REST API
Create a bot API key
Each bot needs its own API key for tracking.
Create a bot to get an API key.
Integrate the REST API
There are two integration points as outlined below.
1. When bot posts to your webhook endpoint
When your bot receives a message, post the data to the following endpoint:
https://tracker.dimensionlabs.io/track?platform=sms&v=11.1.0-rest&type=incoming&apiKey=API_KEY_HERE
Make sure to set the ‘Content-Type’ header to ‘application/json’ and to replace API_KEY_HERE
with your api key.
The data to POST should pass the following data:
{
"text": "Hi, bot",
"userId": "+14155551234",
"platformJson": {
"whateverJson": "any JSON specific to your platform can be stored here"
}
}
Sample cURL
curl -X POST -H "Content-Type: application/json"
-d '{"text":"Hi, bot","userId":"+14155551234","platformJson":{"whateverJson":"any JSON specific to your platform can be stored here"}}'
'https://tracker.dimensionlabs.io/track?platform=sms&v=11.1.0-rest&type=incoming&apiKey=API_KEY'
Notice, you must replace the placeholder API_KEY_HERE
above with your api key.
Note
This is just an example — we accept all the fields at the top of the page.
2. When your bot sends a message
When your bot sends a message, POST to the following endpoint:
https://tracker.dimensionlabs
.io/track?platform=sms&v=11.1.0-rest&type=outgoing&apiKey=API_KEY_HERE
Make sure to set the ‘Content-Type’ header to ‘application/json’ and to replace API_KEY_HERE
with your api key.
The data to POST should pass the following data:
{
"text": "Hello, my human pet",
"userId": "+14155551234",
"platformJson": {
"whateverJson": "any JSON specific to your platform can be stored here"
}
}
Sample cURL
curl -X POST -H "Content-Type: application/json"
-d '{"text":"Hello, my human pet","userId":"+14155551234","platformJson":{"whateverJson":"any JSON specific to your platform can be stored here"}}'
'https://tracker.dimensionlabs.io/track?platform=sms&v=11.1.0-rest&type=outgoing&apiKey=API_KEY_HERE'
Notice, you must replace the placeholder API_KEY_HERE
above with your api key.