Notification API - send.to.channel

Send a web notification message to all active users (to all websockets) who are connected to a specific websocket channel (targeting by key of channel).

API service and action

webntfWebsocket service called via API
send.to.channelAction called on remote API

API request data

domainTarget domain name for notifications
targetTarget websocket channel (key) for notifications
messageNotification message data (defined by JavaScript)

Example request data

array(3) {
    ["domain"]=>
    string(16) "www.websocket.cz"
    ["target"]=>
    string(16) "www.websocket.cz"
    ["message"]=>
    array(14) {
        ["lang"]=>
        string(2) "en"
        ["title"]=>
        string(27) "Test websocket notification"
        ["body"]=>
        string(39) "Notification sent 16.3. 2022 at 23:06:44"
    }
}

Example PHP code for call websocket API

$responseData = $rest2WebSocket->call("webntf", "send.to.channel", [
    "domain" => "www.websocket.cz"
    , "target" => "www.websocket.cz"
    , "message" => [
        "lang" => "en"
        , "title" => "Test websocket notification"
        , "body" => "Notification sent 16.3. 2022 at 23:06:44"
    ]
]);

API response data

array(3) {
    ["status"]=>
    string(2) "OK"
    ["time"]=>
    float(1647438936.566092)
    ["result"]=>
    int(7)	// number of messages sent to client websockets
}

Example of javascript application

For more information on how to handle notifications using a javascript application, see this article.