Page tree
Skip to end of metadata
Go to start of metadata

Websocket is a communications protocol which provides full-duplex communication channels over a TCP connection, allowing interaction between the browser and web server in real-time. The Websocket protocol presents developers with many opportunities for integrating PBX with web applications using JavaScript.

(warning) Version for work: socket.io-client 0.9.0

(warning) All the examples cited below can be found in the library api.onlinepbx.ru/lib/onpbx_ws_api_2.js.

(warning) Library for use on the server: https://www.npmjs.com/package/onpbx-ws-api.

(warning) Mail for your questions: support@onlinepbx.ru.





Connecting

Initializing connection: onpbx.connect({parameters})

onpbx.connected: variable indicating status of connection to WS:// ( true | false )

OptionNoteDescription
domainmandatory

Domain name you would like to connect

keymandatoryAPI key

Example:


{
  "domain": "demo.onpbx.ru",
  "key": "123"
}


Teams

onpbx.command ("team", {parameters}, [callback function])

1. "make_call": Call creation
OptionNoteDescription
frommandatory

Number from which call is placed (number or internal ID)

tomandatory

Recipient (any number)

from_orig_number

Number displayed for receiving party

from_orig_name

Name displayed for receiving party

domain_to

Domain to which call will be sent by default, corresponding to the domain of caller

from_name
Name of caller
gate_from

Call trunk of receiving party (if not given, this will be selected automatically in correspondence to set rules for dialling. If it is stated, these rules will be ignored and the the number will remain unchanged

gate_to

Trunk of calling party

Request:


{
  "from": "77777777777",
  "to": "88001006729",
  "from_orig_number": "88001006729",
  "from_orig_name": "onlinePBX inc.",
  "domain_to": "example.onpbx.ru",
  "from_name": "Vasya",
  "gate_from": "73432048020",
  "gate_to": "73432048020"
}

Response:


{
  "status": true,
  "data": {
    "uuid": "ac1fc137-265e-460b-8f5d-151bd389484e"
  },
  "hash": "wILGN1lQsS3ptIuW"
}



2. "transfer": Transfer an active session to another number
OptionNoteDescription
uuidmandatoryuuid session
tomandatoryTransferee (any number)
gate_to
Analogous to make_call
domain_to
Analogous to make_call

Request:


{
  "uuid": "19ff59fb-2cfc-1230-66b7-00199988ac0c",
  "to": "88001006729",
  "gate_to": "73432048020",
  "domain_to": "example.onpbx.ru"
}

Response:


{
  "status": true,
  "hash": "IBundefinedEGEzdoGXp3KR3"
}
3. "bridge": connect two active sessions
OptionNoteDescription
uuidmandatoryuuid session 1
to_uuidmandatoryuuid session 2

Request:


{
  "uuid": "19ff59fb-2cfc-1230-66b7-00199988ac0c",
  "to_uuid": "c519f6b8-283f-4c1b-bfec-5042a1592d68"
}

Response:


{
  "status": true,
  "hash": "t33Xfa9tcjcN4qA0"
}
4. "eavesdrop": Connect and listen to an active session
OptionNoteDescription
uuidmandatoryuuid session to which you would like to connect
frommandatoryInternal or external number
gate_from
Analogous to make_call

Request:


{
  "uuid": "19ff59fb-2cfc-1230-66b7-00199988ac0c",
  "from": "222",
  "gate_from": ""
}

Response:


{
  "status": true,
  "data": {
    "uuid": "1582f1d4-4afc-468c-8658-b89aaf56edd3"
  },
  "hash": "gUr3K5tdQundefinedqbW4E6"
}
5. "hangup_call": End call
OptionNoteDescription
uuidmandatoryuuid session

Request:


{
  "uuid": "19ff59fb-2cfc-1230-66b7-00199988ac0c"
}

Response:


{
  "status": true,
  "hash": "t33Xfa9tcjcN4qA0"
}
6. "subscribe": Change subscribers to events
OptionNoteDescription
eventsmandatory

Event object to change

calls
Channels/phonecalls
blf
Statuses of extensions
messages
Messages
callback
Callback line
api
Function in development
registration
Registration

Request:


{
  "events": {
    "calls": false,
    "blf": true,
    "messages": false,
    "callback": true,
    "api": false,
    "registration": false
  }
}

Response:


{
  "status": true,
  "text": "Subscriptions are updated",
  "data": {
    "calls": false,
    "blf": true,
    "fax": false,
    "conference": false,
    "messages": false,
    "callback": true,
    "api": false,
    "registration": false
  },
  "hash": "HzYgQQwjE28xkYYw"
}
7. "reboot_phone" (only works on Cisco and some Yealink models)
OptionNoteDescription
nummandatoryPhone number
model
Model of phone (yealink | cisco)

Request:


{
  "num": "222",
  "model": "yealink"
}

Response:


{
  "status": true,
  "hash": "h6zTtouUrY6EYfd6"
}
8. "reloadgw": Reload trunk
OptionNoteDescription
nummandatoryTrunk number

Request:


{
  "num": "73432048020"
}

Response:


{
  "status": true,
  "hash": "D4jah0CA7czPpAhl"
}
9. "sip_message": Send SIP message (not supported by some phones and web clients)
OptionNoteDescription
nummandatoryPhone number
textmandatoryText of message (maximum 200 characters)

Request:


{
  "num": "222",
  "text": "Hello World!"
}

Response:


{
  "status": true,
  "hash": "Qd4PelbvCram9Vni"
}
10. "flush_reg": Delete subscriber registration (will not be able to take calls until re-register)
OptionNoteDescription
nummandatoryPhone number

Request:


{
  "num": "222"
}

Response:


{
  "status": true,
  "hash": "OaEVdkhgL7bBuR2T"
}
11. "trunk_list": List of trunks and their condition (no parameters)
OptionNoteDescription
data
Data variable in callback function
extension
Trunk number
desc
Trunk name
dest
Number of destination in PBX
uri
SIP address
status
Registration status

Since there are no parameters there is no request

Response:


{
  "status": true,
  "data": [
    {
      "extension": "88001006729",
      "desc": "zebra",
      "dest": "6201",
      "uri": "005815@sip.zebra.ru",
      "status": "REGED"
    }
  ],
  "hash": "9lbCrsfPXD6optBT"
}
12. "user_list": List of all registered users (no parameters)
OptionNoteDescription
data
Data variable in callback function
name
Username
local_ip
Local address
local_por
Local port
exp
UNIX timestamp upon completing registration
realm
SIP domain
uid
Internal number
ip
External address
port
External port
agent
User device

Since there are no parameters, there is no request

Response:


{
  "status": true,
  "data": [
    {
      "name": "Vyacheslav",
      "local_ip": "172.27.0.58",
      "local_port": "5060",
      "exp": 1375525567000,
      "realm": "example.onpbx.ru",
      "uid": "222",
      "ip": "213.222.45.85",
      "port": "5060",
      "agent": "Cisco/SPA303-7.4.9c"
    }
  ],
  "hash": "Vlltjwe5XXKfVAa4"
}
13. "message": Send message to other connected clients in this domain
OptionNoteDescription
datamandatoryInformation, which needs to be sent
target
Domain by default. Two values are allowed. “Domain” sends the message to everyone within the domain. “Browser” sends the message to every open window of the sender

Request:


{
  data : "Hi All!"
  target : "domain"
}

Response:


{
  "status": true,
  "hash": "SKP6Gu1cLeJdjxel"
}
14. Error return
OptionDescription
status
textText of error message

Example:


{
  "status": false,
  "text": "CALL_REJECTED",
  "hash": "mAXgxFJundefinedvspIYGfc"
}

To сontents



Events

onpbx.on ("event", function(data){...})

1."connect": Connection to WS://
OptionNoteDescription
data
undefined

This event contains no data.

2. "disconnect": Disconnection from WS://
OptionNoteDescription
data
undefined

This event contains no data.

3. "blf": Status of line (online, busy, calling)
OptionNoteDescription
uid
Internal user number
status
Event status
direction
Direction of call (“in” / “out”)
rank
Priority of tabs in the browser (“master” / “slave”). There is one master and the rest are slaves
other_leg
Second participant
uuid
Unique identifier of session
timestamp
Time of event creation (in the UNIX timestamp format: http://www.unixtimestamp.com/index.php

Example:


data:{
  "uid": "204",
  "status": "ringing",
  "direction": "out",
  "rank": "master",
  "other_leg": "73432048020",
  "uuid": "22c9e591-3784-4c64-8ebf-c8bfcef17776",
  "timestamp": 1452498750
}
4. "registration": Attempts to register user
OptionNoteDescription
uid
User number
agent
User device
state
State of registration: “pre_register”: primary registration request; “register_attempt “: request with login/password; “register”: registration was successful
ip
Internal IP address of device
port
Internal port
expires
Seconds to completion of registration

Example:


data:{
  "uid": 201,
  "agent": "Cisco SPA303-g2",
  "state": "register",
  "ip": "8.8.8.8",
  "port": 5060,
  "expires": 3600
}
5. "channel_create": Creating a new channel
OptionNoteDescription

uuid


Channel identifier
direction
“Direction of channel” relative to PBX (inbound/outbound)
created_stamp
Time of channel creation in the unix timestamp format
state
State of channel
endpoint
End point in PBX
domain
SIP domain
caller_number

caller_name

destination_number

destination_host
SIP domain
gate
Trunk (phone number)
diversion
RDNIS intermediary number when call forwarding

Example:


data:{
  "uuid": "5dc1cdca-9e80-4b94-9633-asdasdadasa",
  "direction": "inbound",
  "created_stamp": 1440864124272,
  "state": "CS_INIT",
  "endpoint": "9090001122",
  "domain": "example.onpbx.ru",
  "caller_number": "9090001122",
  "caller_name": "9090001122",
  "destination_number": "555",
  "destination_host": "555.127.255.XXX",
  "gate": "4951112233",
  "diversion": "555@XXX.145.43.XXX:5061"
}
6. "channel_destroy": Delete channel
OptionNoteDescription
uuid
Channel identifier
direction
“Direction of channel” relative to PBX (inbound/outbound)
created_stamp
Time of channel creation in the unix timestamp format
state
State of channel
endpoint
End point in the PBX
hangup_cause

Reason for hangup —

http://api.onlinepbx.ru/lib/hangup_cause.js

Example:


data:{
  "uuid": "22c9e591-3784-4c64-8ebf-c8bfcef17776",
  "direction": "inbound",
  "created_stamp": "1375466463124",
  "state": "CS_DESTROY",
  "endpoint": "222@example.onpbx.ru",
  "hangup_cause": "NORMAL_CLEARING"
}
7. "channel_answer": Channel is in answer mode
OptionNoteDescription
uuid
Channel identifier
answered_stamp

read_codec

read_rate

read_bitrate

write_codec

write_rate

write_bitrate

Example:


data:{
  "uuid": "22c9e591-3784-4c64-8ebf-c8bfcef17776",
  "answered_stamp": "1375466463124",
  "read_codec": "PCMU",
  "read_rate": "8000",
  "read_bitrate": "64000",
  "write_codec": "PCMA",
  "write_rate": "8000",
  "write_bitrate": "64000"
}
8. "channel_bridge": Connecting channels
OptionNoteDescription
direction
inbound/outbound
aleg_uuid
uuid of chanel A
bleg_uuid
uuid of channel B

Example:


data:{
  "direction": "inbound",
  "aleg_uuid": "22c9e591-3784-4c64-8ebf-c8bfcef17776",
  "bleg_uuid": "129d1446-0063-122c-15aa-001a923f6a0f"
}
9. "channel_application": Performing commands on the channel
OptionNoteDescription
uuid
Channel identifier
application
Currently only supports one command type. In the future there will be more.
application_data
Command argument

Example:


data:{
  uuid : "22c9e591-3784-4c64-8ebf-c8bfcef17776",
  application : "transfer",
  application_data : { ... }
}









Examples of use


You did not find the answer to your question?

Contact our technical support:

+7 (495) 669-67-21
+7 (343) 302-01-37
+7 (343) 646-51-40

Email — support@onlinepbx.ru

Write a comment…