Skip to content

Call API is a front-end layer for managing advanced SIP call flows. It listens for WebSocket connections and talks JSON-RPC 2.0 over them.

License

Notifications You must be signed in to change notification settings

eliakimfelmorais/call-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Call API


The Call API is a front-end for SIP Proxies (such as OpenSIPS), aiming to simplify the management of more advanced SIP call flows. Combining built-in SIP scenarios (such as the ones from RFC 5359) with real-time notifications as the call commands take place, the API is meant to help VoIP system developers build complex SIP services with ease, altogether while providing live reporting for such services.

The API listens for WebSocket connections on ws://localhost:5059/call-api and talks JSON-RPC 2.0 over them.

Installation

    go get github.com/OpenSIPS/call-api

TODO

Configuration

    go get github.com/OpenSIPS/call-api
    
    

Go to the folder config

[root@centos src]# cd call-api/config/

Create folder /etc/call-api and copy these files to them

[root@centos config]# mkdir /etc/call-api/

[root@centos config]# ls -lah
drwxr-xr-x. 2 root root  46 May 30 02:54 .
drwxr-xr-x. 7 root root 164 May 30 02:54 ..
-rw-r--r--. 1 root root 607 May 30 02:54 call-api.yml
-rw-r--r--. 1 root root 294 May 30 02:54 call-cmd.yml

root@centos config]# cp call-api.yml call-cmd.yml /etc/call-api/

***remember to look inside /etc/call-api/call-api.yml to configure with the right mi properties to establish the communication .

Starting The API

[root@centos call-api]# go run main.go
INFO[0000] Listening for JSON-RPC over WebSocket on localhost:5059/call-api ...

If the api start you will get some message like that.

Now you are able to send the requests.

TODO

API Call Commands

Below are the API's commands available for building your JSON-RPC requests. Read the documentation of each command for a listing of its input parameters and their accepted values:

Interacting with the API

By default, the API listens on ws://localhost:5059/call-api. Below is an example way of launching a CallStart command using an API client written in Go:

go run cmd/call-api-client/main.go \
  -method CallStart \
  -params '{"caller": "sip:alice@localhost", "callee": "sip:bob@localhost"}'

JSON-RPC Method Documentation

Once a WebSocket channel is established between the client and the API, communication will take place strictly using JSON messages which follow the JSON-RPC 2.0 request/response/notification protocol. Note that API clients are expected to process notifications from the API, while their launched commands are being handled asynchronously.

CallStart

Parameters

  • "caller" (string, mandatory)
  • "callee" (string, mandatory)

Example JSON-RPC flow:

1) WS client ----------> API

{
    "method": "CallStart",
    "params": {
        "caller": "sip:[email protected]",
        "callee": "sip:[email protected]"
    }

    "id": "831717ed97e5",
    "jsonrpc": "2.0"
}

2) WS client <---------- API

{
    "result": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178",
        "status": "Started"
    }

    "id": "831717ed97e5",
    "jsonrpc": "2.0"
}

3) WS client <---------- API

{
    "method": "Event",
    "params": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178",
        "data": "CALL_ANSWER"
    }

    "jsonrpc": "2.0"
}

4) WS client <---------- API

{
    "method": "Event",
    "params": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178",
        "data": "TRANSFER_ACCEPT"
    }

    "jsonrpc": "2.0"
}

5) WS client <---------- API

{
    "method": "Event",
    "params": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178",
        "data": "CALL_START"
    }

    "jsonrpc": "2.0"
}

6) WS client <---------- API

{
    "method": "Event",
    "params": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178",
        "data": "CALL_ANSWER"
    }

    "jsonrpc": "2.0"
}

7) WS client <---------- API

{
    "method": "Ended",
    "params": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178"
    }

    "jsonrpc": "2.0"
}

CallBlindTransfer

Parameters

  • "callid" (string, mandatory) - the SIP Call-ID of the targeted dialog
  • "leg" (string, mandatory) - which party to transfer. Possible values: "caller", "callee"
  • "destination" (string, mandatory) - SIP URI of the blind transfer target

Example JSON-RPC flow:

# 1) WS client ----------> API

{
    "method": "CallBlindTransfer",
    "params": {
        "callid": "[email protected]",
        "leg": "callee",
        "destination": "sip:[email protected]"
    }

    "id": "831717ed97e5",
    "jsonrpc": "2.0"
}

# 2) WS client <---------- API

{
    "result": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178",
        "status": "Started"
    }

    "id": "831717ed97e5",
    "jsonrpc": "2.0"
}

# 3) WS client <---------- API

{
    "method": "Event",
    "params": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178",
        "data": "TRANSFER_ACCEPT"
    }

    "jsonrpc": "2.0"
}

# 4) WS client <---------- API

{
    "method": "Event",
    "params": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178",
        "data": "CALL_START"
    }

    "jsonrpc": "2.0"
}

# 5) WS client <---------- API

{
    "method": "Ended",
    "params": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178"
    }

    "jsonrpc": "2.0"
}

CallAttendedTransfer

Parameters

  • "callid_a" (string, mandatory) - the SIP Call-ID of the dialog #1
  • "leg_a" (string, mandatory) - which party to transfer from dialog #1. Possible values: "caller", "callee"
  • "callid_b" (string, mandatory) - the SIP Call-ID of the dialog #2
  • "leg_b" (string, mandatory) - which party to transfer from dialog #2. Possible values: "caller", "callee"
  • "destination" (string, mandatory) - SIP URI of the attended transfer's destination

Example JSON-RPC flow:

# 1) WS client ----------> API

{
    "method": "CallAttendedTransfer",
    "params": {
        "callid_a": "[email protected]",
        "leg_a": "caller",
        "callid_b": "0ba2cf53-9a78-41de-8fe6-f2e5bb4d1a1e",
        "leg_b": "callee",
        "destination": "sip:[email protected]"
    }

    "id": "831717ed97e5",
    "jsonrpc": "2.0"
}

# 2) WS client <---------- API

{
    "result": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178",
        "status": "Started"
    }

    "id": "831717ed97e5",
    "jsonrpc": "2.0"
}

# 3) WS client <---------- API

{
    "method": "Event",
    "params": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178",
        "data": "TRANSFER_ACCEPT"
    }

    "jsonrpc": "2.0"
}

# 4) WS client <---------- API

{
    "method": "Event",
    "params": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178",
        "data": "CALL_START"
    }

    "jsonrpc": "2.0"
}

# 5) WS client <---------- API

{
    "method": "Ended",
    "params": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178"
    }

    "jsonrpc": "2.0"
}

CallHold

Parameters

  • "callid" (string, mandatory) - the SIP Call-ID of the target dialog
  • "leg" (string, optional) - party to put on hold ("caller" or "callee"). If missing, both call participants will be put on hold

Example JSON-RPC flow:

# 1) WS client ----------> API

{
    "method": "CallHold",
    "params": {
        "callid": "[email protected]",
        "leg": "caller"
    }

    "id": "831717ed97e5",
    "jsonrpc": "2.0"
}

# 2) WS client <---------- API

{
    "result": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178",
        "status": "Started"
    }

    "id": "831717ed97e5",
    "jsonrpc": "2.0"
}

# 3) WS client <---------- API

{
    "method": "Event",
    "params": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178",
        "data": "CALL_HOLD"
    }

    "jsonrpc": "2.0"
}

# 4) WS client <---------- API

{
    "method": "Ended",
    "params": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178"
    }

    "jsonrpc": "2.0"
}

CallUnHold

Parameters

  • "callid" (string, mandatory) - the SIP Call-ID of the target dialog

Example JSON-RPC flow:

# 1) WS client ----------> API

{
    "method": "CallUnHold",
    "params": {
        "callid": "[email protected]"
    }

    "id": "831717ed97e5",
    "jsonrpc": "2.0"
}

# 2) WS client <---------- API

{
    "result": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178",
        "status": "Started"
    }

    "id": "831717ed97e5",
    "jsonrpc": "2.0"
}

# 3) WS client <---------- API

{
    "method": "Event",
    "params": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178",
        "data": "CALL_UNHOLD"
    }

    "jsonrpc": "2.0"
}

# 4) WS client <---------- API

{
    "method": "Ended",
    "params": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178"
    }

    "jsonrpc": "2.0"
}

CallEnd

Parameters

  • "callid" (string, mandatory) - the SIP Call-ID of the target dialog

Example JSON-RPC flow:

# 1) WS client ----------> API

{
    "method": "CallEnd",
    "params": {
        "callid": "[email protected]"
    }

    "id": "831717ed97e5",
    "jsonrpc": "2.0"
}

# 2) WS client <---------- API

{
    "result": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178",
        "status": "Started"
    }

    "id": "831717ed97e5",
    "jsonrpc": "2.0"
}

# 3) WS client <---------- API

{
    "method": "Ended",
    "params": {
        "cmd_id": "b8179f1e-b4e4-4ac7-9990-4bf64f084178"
    }

    "jsonrpc": "2.0"
}

About

Call API is a front-end layer for managing advanced SIP call flows. It listens for WebSocket connections and talks JSON-RPC 2.0 over them.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 98.3%
  • Makefile 1.7%