Jump to content
Vodia PBX forum
Sign in to follow this  
voltier

Sample working code for Web Socket

Recommended Posts

Just wondering if anybody out there has working code for Web Sockets that they could share. We have looked at Vodia's latest php sample, along with some samples found in the forum e.g. (http://forum.vodia.com/index.php/topic/14660-rest-api-calls-from-javascript/?hl=websocket&do=findComment&comment=42175) however they do not appear to work. We are currently sitting on 5.5.4 of the pbx.

 

Edit:

 

I am expecting to get this:

{"action":"call-state","calls":[{"id":85895,"from":"\"AUTO PARTS\"
But, instead, I am getting the following:
{"action":"user-state","type":"","account":"","domain":"","chatstatus":"online"}
{"action":"user-state","type":"attendants","
Which is not consistent with the REST API documentation.

Share this post


Link to post
Share on other sites

I too am running into this issue. I have found that if I login to the portal then create a connection then it will work as I have a cookie setup. However, if I do not do this then I get the same issue as voltier. I am wondering if there is a query parameter we can pass in on the connection instead of relying on the cookie? The cookie does not work across different domains.

 

However, I do have an example of the web sockets working you just need to login through the login interface and set a session in a cookie on the same domain as your pbx.

 

ie: document.cookie = "session={apikeyfromlogin};path=/;domain={pbxdomain.com}";

 

After that your code should work. Not sure if you are still having problems but this should point you in the right direction if you still need help.

Share this post


Link to post
Share on other sites

You have to login as a user to get a session id before using the websocket API, which can be used to monitor calls or make and hangup calls etc.

 

You can get the session ID during login and then use that token on every subsequent call. An example is given below:
hash = MD5(password);
vars = { name: "auth", value: account + " " + hash };
sessId = putRest("/rest/system/session", vars);
if (sessId != "") {
document.cookie = "session=" + sessId;
}
The account (extension@domain) and password (its MD5 hash is used) are for the user login. To login, you make a REST call to "/rest/system/session" to the PBX with the variables explained above. You will get a session ID which you can then set to a cookie as shown, for all subsequent calls.
I hope that solves the problem for you.
Thanks.

Share this post


Link to post
Share on other sites

I'm trying to implement a live ACD web UI, and I ran into an issue.

The program is on asp.net core 2. I'm using the documentations found here, 

https://doc.vodia.com/third_party

https://doc.vodia.com/websocket

According to the documentations above, I must first obtain the session ID and then open up a websocket connection. I try to obtain a session ID using information from third party documentation, but always receive a response 'false'. How can I debug this, or what could be wrong? A portion of my code,

var url = string.Format("http://ipaddress/rest/system/session");
var encoded_url = HttpUtility.UrlEncode(url);
var uri = new Uri(url);
var base64_hash = Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", "user", "password")));
var client = new RestClient(uri);
var host_address = "myhost";
var response = "";

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

request.Method = "post";
request.Host = host_address;
request.Accept = "*/*";
request.ContentType = "application/json";
request.Headers.Add("Authorization", string.Format("Basic {0}", base64_hash));
request.Headers.Add("DNT", "1");
request.Headers.Add("Origin", string.Format("http://{0}", host_address));

using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
string json = "{\"name\":\"3rd\"," +
"\"username\":\"user\"," +
"\"domain\":\"domain\"}";

streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
}

using (HttpWebResponse resp = request.GetResponse() as HttpWebResponse)
{
var reader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8);
response = reader.ReadToEnd();
}

So the idea is, I obtain the session ID on the backend and insert it into a cookie, and then fire up websocket connection via javascript to receive ACD updates.

I can fetch other information like wallboard, domain users etc, so it doesn't look like a rights issue for my user.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...