Skip to content

Instantly share code, notes, and snippets.

@seven1240
Created July 2, 2013 03:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save seven1240/5906516 to your computer and use it in GitHub Desktop.
Save seven1240/5906516 to your computer and use it in GitHub Desktop.
inbound event socket example
/*
<extension name="400xx">
<condition field="destination_number" expression="^400xx$">
<action application="set" data="my_callback=xx"/>
<action application="park"/>
</condition>
</extension>
<extension name="ask_number">
<condition field="destination_number" expression="^ask_number$">
<action application="read" data="1 4 /tmp/please-input-a-number.wav digits 5000 #"/>
<action application="transfer" data="${digits}"/>
</condition>
</extension>
*/
#include <stdio.h>
#include <stdlib.h>
#include <esl.h>
int main(void)
{
esl_handle_t handle = {{0}};
int i;
int rate = 20;
int total = 100;
int j;
esl_status_t status;
int success = 0;
int fail = 0;
int finished = 0;
esl_global_set_default_logger(6);
esl_connect(&handle, "localhost", 8022, NULL, "ClueCon");
esl_events(&handle, ESL_EVENT_TYPE_PLAIN, "CHANNEL_PARK");
again:
while((status = esl_recv_timed(&handle, 1000)) != ESL_FAIL) {
if (status == ESL_SUCCESS) {
const char *type = esl_event_get_header(handle.last_event, "content-type");
if (type) {
const char *event_name = esl_event_get_header(handle.last_ievent, "Event-Name");
esl_log(ESL_LOG_INFO, "recv event_name: %s\n", event_name);
if (!strcmp(event_name, "CHANNEL_PARK")) {
char buf[1024];
const char *is_callback = esl_event_get_header(handle.last_ievent, "variable_my_callback");
const char *cid = esl_event_get_header(handle.last_ievent, "Caller-Caller-ID-Number");
const char *channel_uuid = esl_event_get_header(handle.last_ievent, "Caller-Unique-ID");
if (is_callback) {
esl_log(ESL_LOG_INFO, "recv call from: [%s] [%s]\n", cid, channel_uuid);
esl_execute(&handle, "log", "ERR recv call", channel_uuid);
sprintf(buf, "api uuid_kill %s\n\n", channel_uuid);
esl_send_recv(&handle, buf);
sleep(3);
#if 0
sprintf(buf, "bgapi originate user/%s ask_number XML default\n\n", cid);
#endif
sprintf(buf, "bgapi originate user/%s read:'1 4 /tmp/please-input-a-number.wav digits 5000 #',transfer:${digits} inline\n\n", cid);
esl_send_recv(&handle, buf);
} else {
esl_log(ESL_LOG_INFO, "not a callback\n");
}
}
}
}
}
esl_disconnect(&handle);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment