Katar SMS
Queue server for sending and receiving SMS.
The library does not do any analysis around whether an SMS is in response to a previous SMS, it simply emits an event when an SMS is received.
Usage
var katarSms = ;var smsQueue = ; // send a new sms { console;}; // listen for sms sent eventsmsQueue;
Since sms queue extends a katar queue instance, all of the original events are still emitted on the smsQueue.
// emitted if sending the sms failedsmsQueue; // emitted if an sms is sentsmsQueue;
Incoming SMS
The sms queue also provides a mechanism for clients to notify the sms queue when an incoming sms is received.
// add an event handler for processing received smssmsQueue;
Clients
Clients can be implemented in any language or platform as long as they implement the HTTP API. The HTTP API for SMS queue is the same as a katar HTTP worker. The only addition to the HTTP worker API is a /receive
route appended to the queue path.
Consider the following sms queue:
var katar = ;var queue = katar;var katarSms = ;var smsQueue = ;
Poll for queued SMS to be sent
A sample request is shown below. See Poll for next queued task for more details.
Request:
POST /v1/queue/sms
{}
Response:
{
tasks: [{ _id: 1, data: { to: '0404123456', msg: 'msg to be sent' }]
}
Mark SMS as sent
A sample request is shown below. See Mark task/tasks as done for more details.
Request:
POST /v1/queue/sms
{
tasks: [
{ _id: 'abc', status: 'done' },
{ _id: 'def', status: 'failed', error: 'some error' }
]
}
Response:
Received SMS
To notify the server of SMS received by the worker agent, send a POST request to /v1/queue/:queue/receive
.
Request:
POST /v1/queue/sms/receive
{
sms: { from: '0404123456', msg: 'msg received' }
}
Response:
The server sends a 204 No Content
status code if there were no errors.