Picture of iqbal
Registered 5 years 279 days
iqbal Thursday, 23 April 2020, 10:16 AM
Talking to the v13 Application Platform using PHP
i want to do some automation work. my Problem is that i want to add Instances of installed applications to AP Manager with PHP scripting. is there a workaround to accomplish that. i am following steps from: http://wiki.innovaphone.com/index.php?title=Howto:Talking_to_the_v13_Application_Platform_using_PHP can i have a direct websockt connection to AP Manager and send instance creation/remove etc. commands.
Picture of Daniel Deterding (innovaphone)
Moderator Registered 15 years 179 days
Daniel Deterding (innovaphone) Friday, 24 April 2020, 08:43 AM
Re: Talking to the v13 Application Platform using PHP
Hi Igbal,

yes, this is possible, although there is no official documentation yet for the websocket messages when talking to the manager.

You need to establish a websocket connection to wss://AP-IP-address/manager
The password here is the administrative password which has been created during the install process of the PBX+AP.
The other variable values like sip, app etc. can be choosen freely for this authentication and the authentication is exactly the same as for any other app.

You can check what is done here if you try to login with a webbrowser on https://AP-IP-address/ manually.

After the login process you can send messages like "mt":"AddInstance" and whatever.
The easiest way is to check, what the manager sends from its UI when you create/delete instances in the browser console.

Greetings,
Daniel


Picture of iqbal
Registered 5 years 279 days
iqbal Friday, 24 April 2020, 04:35 PM
1 of 1 users consider this post helpful
Re: Talking to the v13 Application Platform using PHP
thanks Daniel for your response.
i was able to connect to App Manager with following code:

// login to PBX and devices and users $connector = new AppPlatform\AppServiceLogin( $pbxdns, new AppPlatform\AppUserCredentials($pbxuser, $pbxpw),
array( $managerspec = new AppPlatform\AppServiceSpec("manager")
),true );
$connector->connect();

// manager socket connection if ($connector->getAppAutomaton($managerspec)->getIsLoggedIn())
{
AppPlatform\Log::log("Logged in to app manager");
$managerws = $connector->getAppAutomaton($managerspec)->getWs();
}
else
{
AppPlatform\Log::log("Failed to log in to app manager");
exit;
}
Picture of iqbal
Registered 5 years 279 days
iqbal Tuesday, 28 April 2020, 04:19 PM in response to Daniel Deterding (innovaphone)
Re: Talking to the v13 Application Platform using PHP
Hi Daniel i did managed to connect to App Manager but i am having response time issues. after i send a command, it takes between 60-100 seconds to get a response. i am using alternative connection as below:


class PbxAppLoginAutomaton extends AppPlatform\AppLoginAutomaton
{
protected $pbxUrl;
protected $pbxWS;
function __construct($pbx, AppPlatform\AppServiceCredentials $cred, $useWS = false)
{
$this->pbxUrl = (strpos($pbx, "s://") !== false) ? $pbx :
$this->pbxUrl = ($useWS ? "ws" : "wss") . "://$pbx/manager";
// create websocket towards the well known PBX URI
$this->pbxWS = new AppPlatform\WSClient("PBXWS", $this->pbxUrl); parent::__construct($this->pbxWS, $cred);
}
}
Picture of Daniel Deterding (innovaphone)
Moderator Registered 15 years 179 days
Daniel Deterding (innovaphone) Wednesday, 29 April 2020, 06:50 AM
Re: Talking to the v13 Application Platform using PHP
Can you enable the AppWebsocket tracing on the AP Manager?
Click on the Manager App on the left side in the Manager UI and on "Diagnostics" at the top and enable the "AppWebsocket" trace flag here and maybe Webserver traffic.

If you then create your connection and issue your command, what does the trace of the AP Manager tells you?

Greetings,
Daniel
Picture of iqbal
Registered 5 years 279 days
iqbal Wednesday, 29 April 2020, 11:13 AM
Re: Talking to the v13 Application Platform using PHP

i am getting this from webserver trace. app Manager trace does not have any relavant information about my commands. App Manager answers with "normal shutdown" message.

please see attachment.

webservertrace.txt
Picture of Daniel Deterding (innovaphone)
Moderator Registered 15 years 179 days
Daniel Deterding (innovaphone) Wednesday, 29 April 2020, 11:50 AM
1 of 1 users consider this post helpful
Re: Talking to the v13 Application Platform using PHP
The authentication is completly missing in your webserver trace, so your StartInstance is never processed.

The authentication flow is described here, although the websocket.class.php already handles this (I never used it yet, so I can't tell you more):
https://sdk.innovaphone.com/doc/appwebsocket/AppWebsocket.htm#AppChallenge

Greetings,
Daniel
Picture of iqbal
Registered 5 years 279 days
iqbal Monday, 4 May 2020, 12:05 PM
Re: Talking to the v13 Application Platform using PHP
thanks Daniel for your help. i followed your instructions and can connect and send commands to App Manager. its working little bugy. i can send command,they are executed so far by App manager but i have still problem to receive response from App Manager. The "receive" function in texttalk.class.php is not returning values as expected. sometimes it gives full response, sometimes it only contains [mt] parameter. here response result of 4 commands, that were executed in one script.
Array (
[mt] => AddInstanceResult
)
Array (
[mt] => InstanceUpdated
[appServiceID] => fax
[appName] => fax
[appDomain] => demo.de
[webserverPath] => /demo.de/fax
[dbName] => demo.de_fax
[dbUser] => demo.de_fax
[appInitialStatus] => 1
[appStatus] => 1
[databaseSize] => 7795359
[appError] => )
Array (
[mt] => StartInstanceResult
)
Array (
[mt] => AddInstanceResult
) 
Picture of Wim 4127
Registered 6 years 310 days
Wim 4127 Monday, 4 May 2020, 12:51 PM
1 of 1 users consider this post helpful
Re: Talking to the v13 Application Platform using PHP
The easiest way to see/test messages from/to the platform I think is using nodejs script. Following script logs sent/received messages. Normally, every message sent must be replied by a corresponding Result message received.

Advantage of such a simple script is that if it works here, the issue is probably in your PHP components or code.
If it doesn't work with this minimalistic code, the issue is probably on innovaphone:
- Check if your command and parameters are in line with the documentation, and, watch out for casing of the different values, because it is important
- If it still doesn't work, either the documentation is wrong or a bug in innovaphone.

Save the content to something like main.js and then run as "node main.js" and wait until the PBX connects..

const WebSocket = require('ws')
const wss = new WebSocket.Server({ port: 8080 }) //Make sure to configure your app object to connect this port
wss.on('connection', ws => {
ws.on('message', message => {
var messageObject = JSON.parse(message);

console.log(`RECV <= ${message}`)

if (messageObject.mt == "AppChallenge") {
let response = {
mt: "AppChallengeResult",
challenge: "1234"
};
console.log(`SEND => ${JSON.stringify(response)}`)
ws.send(JSON.stringify(response));
}
else if (messageObject.mt == "AppLogin") {
let response = {
mt: "AppLoginResult",
ok: true
};
console.log(`SEND => ${JSON.stringify(response)}`)
ws.send(JSON.stringify(response));
}
else if (messageObject.mt == "PbxInfo") {
// .... send your message here for testing
}
})
})

Disclaimer: this is just "test code" provided as is, e.g. not cleaned up, and contains some duplicate lines
Picture of Haitham Nasr (innovaphone)
Moderator Registered 9 years 206 days
Haitham Nasr (innovaphone) Monday, 4 May 2020, 02:15 PM in response to iqbal
1 of 1 users consider this post helpful
Re: Talking to the v13 Application Platform using PHP
Hello,
to add an instance the following "AddInstance" message should be sent with the fields:
  • mt: "AddInstance"
  • appServiceID:xxxx
  • appName:xxxx,
  • appDomain:xxxx
  • appPassword:xxxx
  • webserverPath:xxxx
  • dbHost:xxxx
  • dbName:xxxx
  • dbUser:xxxx
  • dbPassword:xxxx
After that, 2 response messages should be expected:
1) "InstanceAdded" message which contains additional instance info
2) "AddInstanceResult" message which indicates that the instance was successfully added. This message contains an "mt" field and an "error" field if adding the instance was not successful




Picture of iqbal
Registered 5 years 279 days
iqbal Tuesday, 19 May 2020, 03:47 PM in response to Daniel Deterding (innovaphone)
Re: Talking to the v13 Application Platform using PHP
hi
can somebody tel me how could i insert PBX Password into "User Admin" App programmatically. because it is mandatory for "User Admin" App to work.
regards
iqbal
Picture of Tomas 1082
Registered 12 years 35 days
Tomas 1082 Tuesday, 4 August 2020, 07:53 PM
Re: Talking to the v13 Application Platform using PHP
Hello,

where you able to find some way to set the pbx password?

When saving the page in the app I see in the console some commands being sent over the websocket. One is

"mt":"CheckPassword", "pbxPassword": "xxxxx".....

but the pbxPassword is some hashed value.

Regards,

Tomas
← You can define your color theme preference here