slock/twilio_example.h

18 lines
524 B
C
Raw Normal View History

2014-08-19 23:10:34 -04:00
#define TWILIO_API_SIZE (500 * sizeof(char))
2014-08-19 17:14:54 -04:00
static int
twilio_send(const char *msg, int async) {
char *cmd = (char *)malloc(TWILIO_API_SIZE);
int r = snprintf(cmd, TWILIO_API_SIZE,
"curl -X POST https://api.twilio.com/2010-04-01/Accounts/{account}/SMS/Messages.json"
" -u {username}:{password}"
" --data-urlencode 'From=+{twilio-number}'"
" --data-urlencode 'To=+{phone-number}'"
" --data-urlencode 'Body=%s'"
"%s", msg, async ? " &" : "");
if (r == -1) return r;
r = system(cmd);
free(cmd);
return r;
}