Sending Messages
One of the main purposes of the Conversations API is to facilitate the sending of messages. The conversations/send
action enables applications to post messages into a conversation with a user.
const basic_auth = `Basic ${ Buffer.from(credentialsId + ':' + credentialsSecret).toString('base64') }`;
request({
uri: "https://snapsmedia.io/api/conversations/send",
method: "POST",
headers: { Authorization: basic_auth },
json: {
snaps_user_id: '',
message_type: '',
payload: {},
agent: {},
},
}, (err, response, body) => {
if (err) return console.error(err);
console.log("status code:", response.statusCode);
console.dir(body, { depth: null });
});
Basic Request Body
There are three required properties when calling conversations/send
.
snaps_user_id
: The ID of the user the message should be sent to.message_type
: One of['text', 'image', 'video', 'file']
.payload
: An object of the message data, see the examples below.
An optional property of agent
may be also be passed.
agent
: An object containing a name and image key.
--name
: The name of the agent.
--image
: An avatar or image to use for the agent.
Depending on channel type support, the agent profile will be posted in the user's conversation. If not passed, but supported by the channel type, the default avatar will appear.
Text
{
snaps_user_id: '5c57084031dc3b00defb25bb',
message_type: 'text',
payload: {
text: 'Hello, World!'
},
agent: {
name: 'Chet',
image: 'https://via.placeholder.com/50'
}
}
Images
{
snaps_user_id: '5c57084031dc3b00defb25bb',
message_type: 'image',
payload: {
image: 'https://via.placeholder.com/500.png'
},
agent: {
name: 'Chet',
image: 'https://via.placeholder.com/50'
}
}
Videos
{
snaps_user_id: '5c57084031dc3b00defb25bb',
message_type: 'video',
payload: {
video: 'https://via.placeholder.com/500.mp4'
},
agent: {
name: 'Chet',
image: 'https://via.placeholder.com/50'
}
}
Files
{
snaps_user_id: '5c57084031dc3b00defb25bb',
message_type: 'file',
payload: {
file: 'https://via.placeholder.com/500.pdf'
},
agent: {
name: 'Chet',
image: 'https://via.placeholder.com/50'
}
}
Updated about 1 year ago
What’s Next