[Freeswitch-users] Custom Channel Variables via C#

Brian Campbell bcxml at hotmail.com
Tue Dec 14 22:20:40 MSK 2010


Thanks Mathieu 
 
I have up dated my code as per your instructions.
 
FreeSwitch answers the call and then does a bridge to my Speech Server application. If there are 10 simultaneous calls going on there would be 20 channels. When I send 'api show channels', I get info back for all 20 channels. How do I go about deciding which one contains the correct uuid for the session that I am trying to set a custom channel variable for ?
 
Here is my code
 
     private void injectCdrCode_ExecuteCode(object sender, EventArgs e)
    {
      try
      {
        TcpClient newClient = new TcpClient();
        // Connect to the port
        newClient.Connect(_host, _port);
        NetworkStream tcpStream = newClient.GetStream();
        byte[] receivedBytes = new byte[newClient.ReceiveBufferSize];
        int bytesRead = tcpStream.Read(receivedBytes, 0, newClient.ReceiveBufferSize);
        string returnData = Encoding.ASCII.GetString(receivedBytes);
        // Authenticate
        byte[] sendBytes = Encoding.ASCII.GetBytes("auth ClueCon\n\n");
        tcpStream.Write(sendBytes, 0, sendBytes.Length);
        receivedBytes = new byte[newClient.ReceiveBufferSize];
        bytesRead = tcpStream.Read(receivedBytes, 0, newClient.ReceiveBufferSize);
        returnData = Encoding.ASCII.GetString(receivedBytes);
        // Get channel info
        sendBytes = Encoding.ASCII.GetBytes("api show channels\n\n");
        tcpStream.Write(sendBytes, 0, sendBytes.Length);
        receivedBytes = new byte[newClient.ReceiveBufferSize];
        bytesRead = tcpStream.Read(receivedBytes, 0, newClient.ReceiveBufferSize);
        returnData = Encoding.ASCII.GetString(receivedBytes);

        // How do I get the proper UUID from the info provided by 'api show channels'
        
        string uuid = '????????'
        
        
        
        // Set the Custom Channel Variable
        sendBytes = Encoding.ASCII.GetBytes("api uuid_setvar " + uuid + " qqOneReach_ApplicationId BRIAN" + "\n\n");
                                                                          
        tcpStream.Write(sendBytes, 0, sendBytes.Length);
        receivedBytes = new byte[newClient.ReceiveBufferSize];
        bytesRead = tcpStream.Read(receivedBytes, 0, newClient.ReceiveBufferSize);
        returnData = Encoding.ASCII.GetString(receivedBytes);
        // Clean everything up
        
        tcpStream.Flush();
        tcpStream.Close();
        newClient.Close();
      }
      catch (Exception ex)
      {
        throw ex;
      }
    }

 
Thanks
 
Brian Campbell
 


From: mrene_lists at avgs.ca
Date: Thu, 2 Dec 2010 12:05:42 -0500
To: freeswitch-users at lists.freeswitch.org
Subject: Re: [Freeswitch-users] Custom Channel Variables via C#


You need to authenticate first.



Trying 127.0.0.1...
Connected to localhost
Escape character is '^]'.
Content-Type: auth/request


auth ClueCon


Content-Type: command/reply
Reply-Text: +OK accepted


api show channels


Content-Type: api/response
Content-Length: 748


uuid,direction,created,created_epoch,name,state,cid_name,cid_num,ip_addr,dest,application,application_data,dialplan,context,read_codec,read_rate,read_bit_rate,write_codec,write_rate,write_bit_rate,secure,hostname,presence_id,presence_data,callstate,callee_name,callee_num,callee_direction,call_uuid
aa6e6bee-1c3b-4493-b824-765c5a15f02c,outbound,2010-12-02 12:03:58,1291309438,loopback/park-a,CS_CONSUME_MEDIA,,0000000000,,park,,,inline,inline,L16,8000,128000,L16,8000,128000,,mrene.local,,,RINGING,,,,c9781e01-667e-446b-93e8-a081f0287d15
78ff4bb6-573e-4a60-a920-bfdb67f3ed6b,inbound,2010-12-02 12:03:58,1291309438,loopback/park-b,CS_EXECUTE,,0000000000,,park,park,,inline,inline,L16,8000,128000,L16,8000,128000,,mrene.local,,,RINGING,,,,


2 total.


Then you can use the uuid_* commands.





Mathieu Rene
Avant-Garde Solutions Inc
Office: + 1 (514) 664-1044 x100
Cell: +1 (514) 664-1044 x200
mrene at avgs.ca






On 2010-12-02, at 10:03 AM, Brian Campbell wrote:

Thanks, the link was very helpful
 
I have taken a look at the link that you provided
 
I assume now that I can use uuid_setvar to accomplish what I want
 
Assuming that the uuid is 53d37581-1f90-44bf-860a-addbc8430e3a, it seems that my code would need to change to
 
 
private void injectCdrCode_ExecuteCode(object sender, EventArgs e)
{
  try
  {
    TcpClient newClient = new TcpClient();
 
    newClient.Connect("127.0.0.1", 8021);
 
    NetworkStream tcpStream = newClient.GetStream();
 
    byte[] sendBytes = Encoding.ASCII.GetBytes("api uuid_setvar 53d37581-1f90-44bf-860a-addbc8430e3a myChannelVariable 12345");
 
    tcpStream.Write(sendBytes, 0, sendBytes.Length);
 
    tcpStream.Close();
 
    newClient.Close();
  }
  catch(Exception ex)
  {
    throw ex;
  }
}

My question now becomes, how do I go about finding out the uuid for the session ? Is that obtainable via mod_event_socket or is there another way ?
 
Thanks
 
Brian 


From: mrene_lists at avgs.ca
Date: Wed, 1 Dec 2010 16:53:53 -0500
To: freeswitch-users at lists.freeswitch.org
Subject: Re: [Freeswitch-users] Custom Channel Variables via C#


Hi,


You can't send XML dialplan actions on the socket and expect FreeSWITCH to understand it, you must follow the event socket protocol.


See http://wiki.freeswitch.org/wiki/Event_socket for more information.




Mathieu Rene
Avant-Garde Solutions Inc
Office: + 1 (514) 664-1044 x100
Cell: +1 (514) 664-1044 x200
mrene at avgs.ca






On 2010-12-01, at 4:46 PM, Brian Campbell wrote:

 
I can set a custom channel variable in my incomming dial plan like this...
 
<action application='set' data='MyChannelVariable=12345' />
 
And it shows up fine in the CDR
 
I am now attempting to use mod_event_socket to set a custom channel variable and have it appear in the CDR
 
Here is the C# code so far, the code is part of a Microsoft Speech Server application that is answering the call
 
private void injectCdrCode_ExecuteCode(object sender, EventArgs e)
{
  try
  {
    TcpClient newClient = new TcpClient();
 
    newClient.Connect("127.0.0.1", 8021);
 
    NetworkStream tcpStream = newClient.GetStream();
 
    byte[] sendBytes = Encoding.ASCII.GetBytes("<action application='set' data='MyChannelVariable=12345' />");
 
    tcpStream.Write(sendBytes, 0, sendBytes.Length);
 
    tcpStream.Close();
 
    newClient.Close();
  }
  catch(Exception ex)
  {
    throw ex;
  }
}
 
After the call is answered, the C# code seems to run fine, but I dont see the custom channel variable in the resulting CDR
 
I figure I am not setting it correctly
 
Can anyone advise on what I am doing wrong ?
 
Thanks
 
 
Brian
 
 
_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users at lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org


_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users at lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-usersUNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org _______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users at lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org


_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users at lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20101214/665020e0/attachment.html 


More information about the FreeSWITCH-users mailing list