DTMF Collection using Event response message system

 #include <esl.h>
#include <cstring>
int main()
{
   char *s,*v;
   esl_handle_t handle = {{0}};
   esl_event_t *event;
    char l_callerUniqueId[1000];
   esl_connect(&handle, "localhost", 8022, NULL, "ClueCon");

   esl_events(&handle, ESL_EVENT_TYPE_PLAIN, "all");
 printf("event is %s \n", handle.last_sr_event);
    esl_send_recv(&handle, "api originate {origination_caller_id_number=2010,originate_timeout=3000}sofia/internal/2009%172.18.1.221 2009\n\n");
    if (handle.connected && handle.last_sr_event) {
        esl_event_dup(&event, handle.last_sr_event);
        event =(esl_event_t *) malloc( sizeof(esl_event_t));
    }
// strcpy(l_callerUniqueId, esl_event_get_header(handle.info_event, "caller-unique-id"));
//    const char* cuuid = esl_event_get_header(event, "core-uuid");
  //  esl_filter(&handle, "unique-id", l_callerUniqueId);
 printf("event is %s eventlength:%d \n", handle.last_sr_event->body, strlen(handle.last_sr_event->body));
  //  esl_execute(&handle, "answer", NULL, NULL);
   // esl_execute(&handle, "play_and_get_digits", "2 4 8000 # /usr/share/freeswitch/sounds/music/8000/partita-no-3-in-e-major-bwv-1006-1-preludio.wav /usr/share/freeswitch/sounds/music/8000/we_are_trying_to_reach.wav my_dtmf \d+", NULL);
   
    s= (char*) calloc(sizeof(char),1280);
    v= (char*) malloc(sizeof(char)*40); 
    strcpy(s,"api uuid_broadcast ");
    strncpy(v,handle.last_sr_event->body + 4,36);
    strcat(s,v);
    strcat(s," '/usr/share/freeswitch/sounds/music/8000/partita-no-3-in-e-major-bwv-1006-1-preludio.wav' aleg &read(3 4 /usr/share/freeswitch/sounds/music/8000/we_are_trying_to_reach.wav' my_dtmf 4000 #)");
    printf("string is :%s\n", s); 
    esl_send_recv(&handle,(const char*) s);
 
    printf("event is %s eventlength:%d \n", handle.last_sr_event->body, strlen(handle.last_sr_event->body));
    while(handle.connected)
    {
          if (esl_recv_event(&handle, 1, NULL) == ESL_SUCCESS) 
          {
               esl_event_t *e = handle.last_ievent ? handle.last_ievent : handle.last_event;
               if (e) 
               {
                  esl_event_dup(&event, e);
                  const char *evtName= esl_event_get_header(e, "event-name");
                 // printf("Event-Name is %s\n Body is %s\n", evtName, handle.last_sr_event->body); 
                  if(strcmp(evtName,"DTMF")==0)
          {
    const char *digit = esl_event_get_header(e,"dtmf-digit");
                            const char *duration = esl_event_get_header(e,"dtmf-duration");
                            printf("DTMF is %s %s\n", digit ,duration);
  }
               }
          }



    }
     esl_disconnect(&handle);
}


Comments

Popular posts from this blog

FreeSWITCH Commands

Sipp integration with FreeSWITCH