Picture of Anton
Registered 5 years 174 days
Anton Tuesday, 17 December 2019, 04:38 PM
Using the PbxAdminApi
Hello, im trying to use the PbxAdminApi. The websocket is sending the json correctly, but i am not getting anything back from the websocket.

Example:
Im sending: src.send({ mt: "GetObject", api: "PbxAdminApi", cn: "username" });
The Appobject does have all rights checked in the PBX settings.
What am i doing wrong? Are there maybe some examples using the PbxAdminApi?

Thank you
Picture of Tomas 1082
Registered 12 years 35 days
Tomas 1082 Wednesday, 25 March 2020, 08:01 AM
Re: Using the PbxAdminApi
I am also having this problem, using the sample from http://wiki.innovaphone.com/index.php?title=Reference13r1:Concept_Talking_to_the_v13_Application_Platform_using_PHP

authenticated directly to the app object with all api rights. Have tried different APIs also, same problem. eg

{"api":"Services","mt":"SubscribeServices"}

or

{"api":"PbxAdminApi","mt":"GetStun"}


See ticket ###276705### for details

Please advice

Regards,

Tomas
Picture of Matthias Schertler (innovaphone)
Moderator Registered 12 years 193 days
Matthias Schertler (innovaphone) Wednesday, 25 March 2020, 07:40 PM
Re: Using the PbxAdminApi
Hello,

I created a small working sample in Javascript and attached it. Maybe it is helpful in some way.

For the Test I created an App object:
  • Name: testapp
  • Password: pwd
  • admin: checked
What the test does:
  • Connect to ws://<pbx-ip>/PBX0/APPS/websocket
  • Do an appwebsocket handshake using the innovaphone.appwebsocket.Connection library:
    • url: "ws://<pbx-ip>/PBX0/APPS/websocket"
    • app: "testapp"
    • password: "pwd"
    • domain: "-"
  • Send an Admin API message
  • Receive the response
I get the following message flow in the browser console:
  • AppWebsocket(testapp) ws://192.168.0.211/PBX0/APPS/websocket
  • testapp: opened ws://192.168.0.211/PBX0/APPS/websocket
  • testapp: send: {"mt":"AppChallenge"}
  • testapp: recv: {"mt":"AppChallengeResult","challenge":"da479308ed52a616"}
  • testapp: send: {"mt":"AppLogin","app":"testapp","domain":"-","sip":"testapp","guid":"00000000000000000000000000000000","dn":"Admin","digest":"20e07ba4a6d72d2c8045c97b1b09857fa27e8de1d4d7456c5890f4635da1dccb","pbxObj":"testapp"}
  • testapp: recv: {"mt":"AppLoginResult","ok":true}
  • testapp: send: {"api":"PbxAdminApi","mt":"GetStun"}
  • testapp: recv: {"api":"PbxAdminApi","mt":"GetStunResult","stun":"stun.innovaphone.com"}
  • Success!
  • testapp: closing
  • testapp: closed
Does that differ from the message flow you see?
test.zip
Picture of Christoph Künkel (innovaphone)
Moderator Registered 15 years 190 days
Christoph Künkel (innovaphone) Wednesday, 25 March 2020, 10:53 PM
Re: Using the PbxAdminApi
Matthias,

I took the "official" PHP sample and modified it so it sends the "GetStunResult" message to the PBX. The login to the PBX works well but there is no response to the PbxAdminResult.

The message flow is as follows:
25.03.2020 22:40:20.8373 0.012 0000.012 smsg AppPlatform\Transitioner: sent->PBXWS {"mt":"Login","type":"session","userAgent":"websocket.class.php (PHP WebSocket CKL-CELSIUS-W11)"} 25.03.
25.03.2020 22:40:20.8377 0.000 0000.013 smsg AppPlatform\Transitioner: received<-PBXWS {"mt":"Authenticate","type":"session","method":"digest","domain":"dvl-ckl2.net","challenge":"12ee8cabc6ecb09f"} 25.03.
25.03.2020 22:40:20.8379 0.000 0000.013 smsg AppPlatform\Transitioner: sent->PBXWS {"mt":"Login","method":"digest","type":"session","username":"fe2f0cd5c27b5e0119980090334000b3","nonce":"8cd1584f38fd23c4","userAgent":"websocket.class.php (PHP WebSocket CKL-CELSIUS-W11)","response":"9ca09872b31117a581bbf0171e21f4cab46cf7e527ab07850fc5d59f2d74971d"} 25.03.
25.03.2020 22:40:20.8391 0.001 0000.014 smsg AppPlatform\Transitioner: received<-PBXWS {"mt":"LoginResult","info":{"user":{"domain":"dvl-ckl2.net","sip":"ckl","guid":"6fedb5cfe9435e01d0c70090334000b3","dn":"Christoph Künkel","num":"","email":"dvl-ckl2@class.local","prefix":{"intl":"000","ntl":"00","subs":"0","area":"621","country":"49"}}},"digest":"aa0fed9564d57451822ec790a73a3bf8e6827d79a0898fb93467a0cf542b3f76"} 25.03.
25.03.2020 22:40:20.8392 0.000 0000.014 runtime AppPlatform\UserPBXLoginWithAppAutomaton(UserPBXLogin): Successfully logged-in to PBX 172.31.31.2 as ckl 25.03.
25.03.2020 22:40:20.8392 0.000 0000.014 smsg AppPlatform\Transitioner: sent->PBXWS {"mt":"SubscribeApps"} 25.03.
25.03.2020 22:40:20.8393 0.000 0000.014 smsg AppPlatform\Transitioner: received<-PBXWS {"mt":"SessionAdded","id":"fe2f0cd5c27b5e0119980090334000b3","info":{"current":true,"userAgent":"websocket.class.php (PHP WebSocket CKL-CELSIUS-W11)","timestamp":1585172421000,"code":5027}} etc. 25.03.
25.03.2020 22:40:20.8400 0.000 0000.015 smsg AppPlatform\Transitioner: received<-PBXWS {"mt":"UpdateOwnPresence","presence":[{"contact":"tel:","activity":"","status":"closed"},{"contact":"im:","activity":"","status":"open"}]} 25.03.
25.03.2020 22:40:20.8401 0.000 0000.015 smsg AppPlatform\Transitioner: received<-PBXWS {"mt":"UpdateAppsInfo","app":{"name":"alarms","title":"Alarms","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/events/innovaphone-alarms"}} 25.03.
25.03.2020 22:40:20.8402 0.000 0000.015 smsg AppPlatform\Transitioner: received<-PBXWS {"mt":"UpdateAppsInfo","app":{"name":"ap","title":"AP","url":"https://apps.dvl-ckl2.net/manager/manager-domain-api","info":{ "hidden":true,"apis":{"com.innovaphone.manager":{}}}}} etc. 25.03.
25.03.2020 22:40:20.9090 0.000 0000.084 smsg AppPlatform\Transitioner: received<-PBXWS {"mt":"UpdateAppsComplete","deviceApps":[{"name":"phone","title":"Phone","deviceapp":"phone"},{"name":"rcc","title":"Rcc","deviceapp":"rcc"},{"name":"softphone","title":"Softphone","deviceapp":"softphone"}],"selected":"pbxmanager,chat,businesshours,apps,devices,users,users-admin,events,alarms,logging,voicemail-en,files,backup-files,reporting,calllist,fax,contacts,contacts-admin,calendar-admin"} 25.03.
25.03.2020 22:40:20.9091 0.000 0000.084 smsg AppPlatform\UserPBXLoginWithAppAutomaton(UserPBXLogin): posting UserPBXLogin->: {"mt":"LoginResult","info":{"user":{"domain":"dvl-ckl2.net","sip":"ckl","guid":"6fedb5cfe9435e01d0c70090334000b3","dn":"Christoph Künkel","num":"","email":"dvl-ckl2@class.local","prefix":{"intl":"000","ntl":"00","subs":"0","area":"621","country":"49"}}},"digest":"aa0fed9564d57451822ec790a73a3bf8e6827d79a0898fb93467a0cf542b3f76","_sourcename":"UserPBXLogin","sessionkeys":null} 25.03.
25.03.2020 22:40:20.9091 0.000 0000.084 runtime AppPlatform\UserPBXLoginWithAppAutomaton(UserPBXLogin): Successfully logged-in to PBX 172.31.31.2 as ckl 25.03.
25.03.2020 22:40:20.9093 0.000 0000.084 smsg AppPlatform\Transitioner: sent->PBXWS {"mt":"SubscribeApps"} 25.03.
25.03.2020 22:40:20.9094 0.000 0000.084 smsg AppPlatform\UserPBXLoginWithAppAutomaton(UserPBXLogin): posting UserPBXLogin->: {"mt":"UserPBXLoginSuccess","results":{"loginMsg":{"mt":"Login","method":"digest","type":"session","username":"fe2f0cd5c27b5e0119980090334000b3","nonce":"8cd1584f38fd23c4","userAgent":"websocket.class.php (PHP WebSocket CKL-CELSIUS-W11)","response":"9ca09872b31117a581bbf0171e21f4cab46cf7e527ab07850fc5d59f2d74971d","password":"rkg+1iDszg1E+emIIcKrga8"},"loginResultMsg":{"mt":"LoginResult","info":{"user":{"domain":"dvl-ckl2.net","sip":"ckl","guid":"6fedb5cfe9435e01d0c70090334000b3","dn":"Christoph Künkel","num":"","email":"dvl-ckl2@class.local","prefix":{"intl":"000","ntl":"00","subs":"0","area":"621","country":"49"}}},"digest":"aa0fed9564d57451822ec790a73a3bf8e6827d79a0898fb93467a0cf542b3f76","_sourcename":"UserPBXLogin","sessionkeys":null},"UpdateAppsMsg":{"apps":[{"name":"alarms","title":"Alarms","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/events/innovaphone-alarms"},{"name":"ap","title":"AP","url":"https://apps.dvl-ckl2.net/manager/manager-domain-api","info":{"hidden":true,"apis":{"com.innovaphone.manager":{}}}},{"name":"apps","title":"Apps","url":"https://apps.dvl-ckl2.net/manager/manager"},{"name":"backup-files","title":"Backup Files","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/backup-files/innovaphone-files"},{"name":"businesshours","title":"Business hours","url":"../../APPS/businesshours/app_bool","inline":true,"info":{"presence":true}},{"name":"calendar-admin","title":"Calendar Admin","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/calendar/innovaphone-calendaradmin"},{"name":"calllist","title":"Call List","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/reporting/innovaphone-calllist","info":{}},{"name":"calllist-api","title":"CallListApi","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/reporting/innovaphone-calllistapi","info":{"hidden":true,"apis":{"com.innovaphone.calllist":{}}}},{"name":"chat","title":"Chat","url":"../../APPS/chat/chat","inline":true,"info":{"apis":{"com.innovaphone.chat":{},"com.innovaphone.notificationhandler":{}},"wake":["chat"],"presence":true}},{"name":"contacts","title":"Contacts","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/contacts/innovaphone-contacts"},{"name":"contacts-admin","title":"Contacts Admin","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/contacts/innovaphone-contacts-admin"},{"name":"contacts-api","title":"ContactsApi","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/contacts/innovaphone-contacts-searchapi","info":{"hidden":true,"apis":{"com.innovaphone.search":{}}}},{"name":"devices","title":"Devices","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/devices/innovaphone-devices","info":{"apis":{"com.innovaphone.devicesui":{}}}},{"name":"devices-api","title":"DevicesApi","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/devices/innovaphone-devices-api","info":{"hidden":true,"apis":{"com.innovaphone.devices":{}}}},{"name":"events","title":"Events","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/events/innovaphone-eventsapp"},{"name":"fax","title":"Fax","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/fax/innovaphone-fax","inline":true,"info":{"presence":true}},{"name":"files","title":"Files","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/files/innovaphone-files"},{"name":"files-api","title":"FilesApi","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/files/innovaphone-files-api","info":{"hidden":true,"apis":{"com.innovaphone.files":{"info":{"announcements":{"url":""}}}}}},{"name":"logging","title":"Logging","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/events/innovaphone-logging"},{"name":"pbxmanager","title":"PbxManager","url":"../../APPS/app_manager/app_manager","inline":true},{"name":"profile","title":"Profile","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/usersapp/innovaphone-profile","info":{}},{"name":"reporting","title":"Reporting","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/reporting/innovaphone-reporting"},{"name":"users","title":"Users","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/usersapp/innovaphone-users"},{"name":"users-admin","title":"Users Admin","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/usersapp/innovaphone-usersadmin"},{"name":"users-apis","title":"UsersApi","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/usersapp/innovaphone-usersapis","info":{"hidden":true,"apis":{"com.innovaphone.search":{},"com.innovaphone.avatar":{"info":{"filename":"picture","token":"fa37JncCHryDsbzayy4cBWDxS22JjzhMaiRrV41mtzxlYvKWrO72tK0LK0e1zLOZ","domain":"dvl-ckl2.net"}}}}},{"name":"voicemail-en","title":"Voicemail en","url":"https://apps.dvl-ckl2.net/dvl-ckl2.net/voicemail_en/innovaphone-voicemail","inline":true,"info":{"presence":true}}]},"updateAppsComplete":true},"_sourcename":"UserPBXLogin"} 25.03.
25.03.2020 22:40:20.9600 0.050 0000.135 runtime script: Logged in to PBX 25.03.
25.03.2020 22:40:20.9601 0.000 0000.135 debug AppPlatform\Transitioner: transitioning PbxApiSample(PBX) from Initial via ReceiveInitialStart 25.03.
25.03.2020 22:40:20.9603 0.000 0000.135 smsg AppPlatform\Transitioner: sent->PBXWS {"mt":"GetStun","api":"PbxAdminApi"} 25.03.
25.03.2020 22:40:20.9604 0.000 0000.135 debug AppPlatform\Transitioner: callable 'ReceiveInitialStart' returns '' 25.03.
25.03.2020 22:40:25.9614 5.000 0005.136 debug AppPlatform\Transitioner: socket select timeout 25.03.
25.03.2020 22:40:25.9615 0.000 0005.136 debug AppPlatform\Transitioner: all but 1 automatons finished - end 
I think the difference is that here we log in to the PBX as a user and you are logging in as an App. Is that right?

Christoph
Picture of Matthias Schertler (innovaphone)
Moderator Registered 12 years 193 days
Matthias Schertler (innovaphone) Wednesday, 25 March 2020, 11:44 PM
1 of 1 users consider this post helpful
Re: Using the PbxAdminApi
Hi Christoph,

yes you are right. It looks we are using two different types of websocket connection and that's reason why it does not work.

In your message flow a I see a login using the myApps protocol to a user object. The protocol only supports user login, getting app information and authenticating against apps.

In order to use the PBX APIs an appwebsocket connection to /PBX0/APPS/websocket is needed. The Login message must contain the name of the app object (e.g. "app":"testapp").

The appwebsocket protocol is described here: http://sdk.innovaphone.com/doc/appwebsocket/AppWebsocket.htm

Matthias

Picture of Christoph Künkel (innovaphone)
Moderator Registered 15 years 190 days
Christoph Künkel (innovaphone) Thursday, 26 March 2020, 12:05 AM
Re: Using the PbxAdminApi
That was it!

In the PHP sample code, we aim at loggin in to an AppService which is not provided by the PBX itself. This is done using the AppServiceLogin automaton.

However, in our case, we want to access an AppService which actually is provided by the PBX itself (PbxAdminApi). For this, we need to change two things:
  • We need to use a different URL (PBX0/APPS/websocket instead of PBX0/APPCLIENT/130000/websocket)
  • we need to use the protocol implemented in the AppLoginAutomaton automaton
The AppServiceLogin automaton b.t.w. also uses AppLoginAutomaton internally, but to authenticate towards the App service (such as Users or Devices).

I have attached sample code. Be sure to modify the PBX's IP address, the App objects name and password to suit your setup (in the call to PbxAppLoginAutomaton)! The App object needs the flags Matthias mentioned above (although I am not sure why it needs the admin flag to be able to use PbxAdminApi, Matthias, any insights?). It's URL property is irrelevant.

Have fun, Christoph

pbxapi.php
Picture of Matthias Schertler (innovaphone)
Moderator Registered 12 years 193 days
Matthias Schertler (innovaphone) Thursday, 26 March 2020, 12:18 AM
Re: Using the PbxAdminApi
Nice! smile

The naming of the flags under "Grant access to APIs" seems to be a bit inconsistent. "Admin" stands for the "PbxAdminApi", but "PbxApi" stands for "PbxApi". wink

Matthias
Picture of Christoph Künkel (innovaphone)
Moderator Registered 15 years 190 days
Christoph Künkel (innovaphone) Thursday, 26 March 2020, 12:18 AM in response to Matthias Schertler (innovaphone)
Re: Using the PbxAdminApi
Matthias,

I think we should add the URL ( PBX0/APPS/websocket ) to the protocol description. At least, I haven't seen it in the page you mentioned. The only place I've seen it is in the RCC tutorial. Or is there another place to find'em?

Christoph
Picture of Matthias Schertler (innovaphone)
Moderator Registered 12 years 193 days
Matthias Schertler (innovaphone) Thursday, 26 March 2020, 01:00 AM
Re: Using the PbxAdminApi
Good point. Added it to the documentation. Will be there in the next service release.
Picture of Christoph Künkel (innovaphone)
Moderator Registered 15 years 190 days
Christoph Künkel (innovaphone) Thursday, 26 March 2020, 01:05 AM
Re: Using the PbxAdminApi
cool!
I just uploaded the new PHP sample code for the PbxAPIs to download.png download.innovaphone.com: ice/wiki-src/
Picture of Tomas 1082
Registered 12 years 35 days
Tomas 1082 Thursday, 26 March 2020, 08:05 AM
Re: Using the PbxAdminApi
HI, thanks for your involvement guys smile

will try your code soon.

Another question arose yesterday, regarding the apis. Is it possible using api's to send a message/chat to user(s)? The requirement would be that myApps wakes up when in background.

br,

Tomas


Picture of Matthias Schertler (innovaphone)
Moderator Registered 12 years 193 days
Matthias Schertler (innovaphone) Thursday, 26 March 2020, 09:49 AM
Re: Using the PbxAdminApi
Hi Tomas,

Yes, this shoud be possible using the PbxSignal protocol. I've not used it before, but I imagine the flow should be something like that:

Create a registration on the PBX:
  • send: { api: "PbxSignal", mt: "Register", ... }
  • recv: { api: "PbxSignal", mt: "RegisterResult", ... }
Start a chat call (without media):
  • send: { api: "PbxSignal", mt: "Signal", call: 1, sig: { type: "setup", cd: { sip: "userxy" }, fty: [ type: "im_setup", ...] }
Send the chat message:
  • send: { api: "pbxSignal", mt: "Signal", call: 1, sig: { type: "facility", fty: [ type: "im_message", ... ] }
However I did not try it, so this might not be completely correct.

You can find the documentation about that API here:
BR
Matthias
Picture of Anton
Registered 5 years 174 days
Anton Thursday, 3 December 2020, 04:48 PM in response to Matthias Schertler (innovaphone)
Re: Using the PbxAdminApi
Hi Matthias,

I have tried your code to connect and it definitely helped, I can use the PbxAdminApi.

Is there a way to get the pbx-ip without setting it manually.
Like the "start.url" in sample App after creating a new project.

Regards,
Anton
← You can define your color theme preference here