Register Event Handler
curl --request POST \
--url https://{host}/Agent/Xmpp/RegisterEventHandler \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Referer: <referer>' \
--data '
{
"tabId": "<string>",
"localName": "<string>",
"namespace": "<string>",
"type": "<string>",
"function": "<string>"
}
'import requests
url = "https://{host}/Agent/Xmpp/RegisterEventHandler"
payload = {
"tabId": "<string>",
"localName": "<string>",
"namespace": "<string>",
"type": "<string>",
"function": "<string>"
}
headers = {
"Referer": "<referer>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
Referer: '<referer>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
tabId: '<string>',
localName: '<string>',
namespace: '<string>',
type: '<string>',
function: '<string>'
})
};
fetch('https://{host}/Agent/Xmpp/RegisterEventHandler', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{host}/Agent/Xmpp/RegisterEventHandler",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'tabId' => '<string>',
'localName' => '<string>',
'namespace' => '<string>',
'type' => '<string>',
'function' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Referer: <referer>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{host}/Agent/Xmpp/RegisterEventHandler"
payload := strings.NewReader("{\n \"tabId\": \"<string>\",\n \"localName\": \"<string>\",\n \"namespace\": \"<string>\",\n \"type\": \"<string>\",\n \"function\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Referer", "<referer>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{host}/Agent/Xmpp/RegisterEventHandler")
.header("Referer", "<referer>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"tabId\": \"<string>\",\n \"localName\": \"<string>\",\n \"namespace\": \"<string>\",\n \"type\": \"<string>\",\n \"function\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{host}/Agent/Xmpp/RegisterEventHandler")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Referer"] = '<referer>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"tabId\": \"<string>\",\n \"localName\": \"<string>\",\n \"namespace\": \"<string>\",\n \"type\": \"<string>\",\n \"function\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{}XMPP messaging
Register Event Handler
Registers (or unregisters) an event handler on the client, that gets called when the account receives an XMPP message of a given type.
POST
/
Agent
/
Xmpp
/
RegisterEventHandler
Register Event Handler
curl --request POST \
--url https://{host}/Agent/Xmpp/RegisterEventHandler \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Referer: <referer>' \
--data '
{
"tabId": "<string>",
"localName": "<string>",
"namespace": "<string>",
"type": "<string>",
"function": "<string>"
}
'import requests
url = "https://{host}/Agent/Xmpp/RegisterEventHandler"
payload = {
"tabId": "<string>",
"localName": "<string>",
"namespace": "<string>",
"type": "<string>",
"function": "<string>"
}
headers = {
"Referer": "<referer>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
Referer: '<referer>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
tabId: '<string>',
localName: '<string>',
namespace: '<string>',
type: '<string>',
function: '<string>'
})
};
fetch('https://{host}/Agent/Xmpp/RegisterEventHandler', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{host}/Agent/Xmpp/RegisterEventHandler",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'tabId' => '<string>',
'localName' => '<string>',
'namespace' => '<string>',
'type' => '<string>',
'function' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Referer: <referer>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{host}/Agent/Xmpp/RegisterEventHandler"
payload := strings.NewReader("{\n \"tabId\": \"<string>\",\n \"localName\": \"<string>\",\n \"namespace\": \"<string>\",\n \"type\": \"<string>\",\n \"function\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Referer", "<referer>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{host}/Agent/Xmpp/RegisterEventHandler")
.header("Referer", "<referer>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"tabId\": \"<string>\",\n \"localName\": \"<string>\",\n \"namespace\": \"<string>\",\n \"type\": \"<string>\",\n \"function\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{host}/Agent/Xmpp/RegisterEventHandler")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Referer"] = '<referer>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"tabId\": \"<string>\",\n \"localName\": \"<string>\",\n \"namespace\": \"<string>\",\n \"type\": \"<string>\",\n \"function\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{}Overview
Registers (or unregisters) an event handler on the client, that gets called when the account receives an XMPP message of a given type. When such a message is received that matches a registered event handler, the message is pushed as a client event to the client, instead of being stored on the broker, as an offline message. Note: For client events to be received on the client, you need to include the /Events.js javascript file on the page. This javascript file will register the current tab with the server, and enable it to receive asynchronous events from the server. If you are hosting the page on one server, and use the Agent API and Events API from another server, you need to include a meta header on the page, information the /Events.js javascript file where it will register itself to receive client events. To use this neuron, add the following to the HTML header of your page: You also need to inform the AgentAPI that you want to use another host, than the server used to host the page. You do this by making a call to AgentAPI.IO.SetHost(Host,Secure) as follows:Authentication
Requires a valid JWT bearer token.Notes
This endpoint uses the request schema notation described in Pattern matching.Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Headers
Your application's HTTPS URL, for example https://app.example.com/. Include this header on every Agent API request, including backend calls, login, and account creation. Browser clients must use a referrer policy that sends the application origin. See /neuron-api/api-basics#required-referer-header.
Response
200 - application/json
Success
The response is of type object.