Sending notifications
You can trigger notifications from Engagespot in two ways. One is to directly hardcode the notifications in your API call, or the second is to create templates in the Engagespot console and then trigger those templates via API. The latter is recommended because it allows you to decouple your notification content from the code.
Triggering hardcoded notifications
You can trigger hardcoded notifications using our REST API or a client library of your choice. Make sure to create the recipient/user before sending a notification to them. If you haven't created a user, read this guide first.
- Curl
- Nodejs
- PHP
- Python
- Rust
- Ruby
curl -X POST 'https://api.engagespot.co/v3/notifications' \
-H 'X-ENGAGESPOT-API-KEY: ENGAGESPOT_API_KEY' \
-H 'X-ENGAGESPOT-API-SECRET: ENGAGESPOT_SECRET_KEY' \
-H 'Content-Type: application/json' \
-d '{ "notification": { "title": "Rose accepted your friend request" }, "sendTo":{"recipients": ["unique-id-of-recipient-user"] } }'
import { EngagespotClient } from '@engagespot/node';
const client = EngagespotClient({
apiKey: 'ENGAGESPOT_API_KEY',
apiSecret: 'ENGAGESPOT_SECRET_KEY',
});
client.send({
notification: {
title: 'Agent X commented on your support ticket #T-793465',
},
sendTo: {
recipients: ['unique-id-of-recipient-user'],
},
});
use Engagespot\\EngagespotClient;
$engagespot = new EngagespotClient('ENGAGESPOT_API_KEY', 'ENGAGESPOT_SECRET_KEY');
$notificationData = [
'notification' => [
'title' => 'This is an example message!',
],
'sendTo' => [
'recipients' => ['unique-id-of-recipient-user'],
],
];
$response = $engagespot->send($notificationData);
from engagespot import Engagespot
client = Engagespot(api_key="ENGAGESPOT_API_KEY", api_secret="ENGAGESPOT_SECRET_KEY")
send_request = {
"notification": {
"title":"Test from Python library🔥"
},
"recipients":["unique-id-of-recipient-user"]
}
response = client.send(send_request)
use engagespot::{Engagespot, NotificationBuilder};
// A reactor like tokio or async-std is required to run the async code.
#[tokio::main(flavor = "current_thread")]
async fn main() {
// initialize engagespot client by passing the api_key and api_secret
let client = Engagespot::new("ENGAGESPOT_API_KEY", "ENGAGESPOT_SECRET_KEY");
let notification = NotificationBuilder::new("title", &vec!["unique-id-of-recipient-user".to_string()]).build();
let response = client.send(¬ification).await.unwrap_or_else(|err: String| format!("Error: {}", err));
}
require 'engagespot'
engagespot = Engagespot.new(api_key:"ENGAGESPOT_API_KEY", api_secret:"ENGAGESPOT_SECRET_KEY")
send_request = {
notification:{
title: "Test notification from Ruby",
},
recipients:['unique-id-of-recipient-user']
}
response = engagespot.send(send_request)
When you trigger a hardcoded notification, the message will be sent across all channels enabled in your Engagespot console.
You can override this configuration through the override
property in the API request.
Sending notifications using third party plugins
Triggering templated notifications
To learn more about templates, read this guide first. To send a templated notification, the steps are exactly the same, except that you should replace the title
field with templateIdentifier
.
For example:
import { EngagespotClient } from '@engagespot/node';
const client = EngagespotClient({
apiKey: 'ENGAGESPOT_API_KEY',
apiSecret: 'ENGAGESPOT_SECRET_KEY',
});
client.send({
notification: {
templateIdentifier: 'template-identifier-copied-from-engagespot-console',
},
sendTo: {
recipients: ['unique-id-of-recipient-user'],
},
});