Producer Service
Producer Events Service Rest API
https://producer.events.newtral.es/swagger
WebSocket Consumer Service
Consumer Events Service WebSocket API
https://consumer.events.newtral.es/swagger
Producer Events Service Rest API
https://producer.events.newtral.es/swagger
Consumer Events Service WebSocket API
https://consumer.events.newtral.es/swagger
Producer Service API, is a Rest API that implements methods to produce the events necessary to send claim detection and matching requests.
Consumer Service API, is a Websocket API to which the client subscribes to receive responses to claims detection and claim matching requests.
You need an apiKey, each client receives its apiKey when the client registers.
Remember to change {ApiKey} to your Client apiKey in the following code.
curl -X 'POST' \
'https://producer.events.newtral.es/claim-detection/statements' \
-H 'accept: application/json' \
-H 'tenant-api-key: {ApiKey}' \
-H 'Content-Type: application/json' \
-d '{
"sentences": [
"I like the sun.",
"I like the moon."
]
}'
curl -X 'POST' \
'https://producer.events.newtral.es/find-claims/resource/text' \
-H 'accept: application/json' \
-H 'tenant-api-key: {ApiKey}' \
-H 'Content-Type: application/json' \
-d '{
"text": "I like the sun. I like the moon"
}'
curl -X 'POST' \
'https://producer.events.newtral.es/claim-detection/resource/article' \
-H 'accept: application/json' \
-H 'tenant-api-key: {ApiKey}' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://www.newtral.es/trump-app-asilo/20240915/"
}'
curl -X 'POST' \
'https://producer.events.newtral.es/find-claims/resource/tweet' \
-H 'accept: application/json' \
-H 'tenant-api-key: {ApiKey}' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://x.com/jack/status/20"
}'
curl -X 'POST' \
'https://producer.events.newtral.es/claim-detection/resource/image' \
-H 'accept: application/json' \
-H 'tenant-api-key: {ApiKey}' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://jeroen.github.io/images/testocr.png"
}'
curl -X 'POST' \
'https://producer.events.newtral.es/find-claims/resource/media' \
-H 'accept: application/json' \
-H 'tenant-api-key: {ApiKey}' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://videos.bannerbear.com/completed/movie-x62aV0wjn3pvwOYkm1.mp4"
}'
Remember to change {ApiKey} to your Client apiKey in the following code.
/* Install dependencies */
npm install "socket.io-client"
/* Example */
import { io } from "socket.io-client";
const socket = io('wss://consumer.events.newtral.es');
const ApiKey = {ApiKey};
function subscribeToTopic() {
if (!socket.connected) {
socket.connect();
}
socket.emit('subscribeToTopic', { apiKey: ApiKey });
}
function unsubscribeToTopic() {
socket.emit('unsubscribeAll', { apiKey: ApiKey });
}
socket.on('connect', () => {
console.log('WebSocket connected');
subscribeToTopic();
});
socket.on('reply-message', (message) => {
console.log(message);
});
socket.on('subscribed', () => {
console.log('Subscribed');
});
socket.on('unsubscribed', () => {
socket.disconnect();
console.log('Unsubscribed every consumer');
});
/* Install dependencies */
pip install "python-socketio[asyncio_client]"
/* Example */
import asyncio
import socketio
from typing import Any, Optional
socket = socketio.AsyncClient()
endpoint = "wss://consumer.events.newtral.es"
apiKey = {ApiKey};
async def connect():
await socket.connect(endpoint, retry=True)
await subscribe_topic()
await socket.wait()
async def subscribe_topic():
await socket.emit("subscribeToTopic", {"apiKey": apiKey})
async def unsubscribe_topic():
await socket.emit("unsubscribeAll", {"apiKey": apiKey})
@socket.event
async def connected():
print("connection established")
@socket.event
async def connect_error(data):
print(f"The connection failed! {data}")
@socket.event
async def disconnect():
print("I'm disconnected!")
@socket.on("connect")
async def suscribe():
print("WebSocket connected")
@socket.on("reply-message")
async def messages(data):
print(data)
@socket.on("subscribed")
async def subscribed(data):
print(f'Subscribed to partition: {data["partition"]}')
@socket.on("unsubscribed")
async def unsubscribed(data: Optional[Any]):
print("Unsubscribed every consumer")
await socket.disconnect()
if __name__ == "__main__":
asyncio.run(connect())
/* Install dependencies */
composer require "elephantio/elephant.io"
/* Example */
require "vendor/autoload.php";
use ElephantIO\Client as Elephant;
$endpoint = "https://consumer.events.newtral.es";
$apiKey = {ApiKey};
$client = Elephant::create($endpoint);
$client->connect();
$disconnect = false;
echo "WebSocket connected\n";
function subscribeToTopic($client, $apiKey)
{
$client->emit("subscribeToTopic", array("apiKey" => $apiKey));
}
function unsubscribeToTopic($client, $apiKey)
{
global $disconnect;
$disconnect = true;
$client->emit("unsubscribeAll", array("apiKey" => $apiKey));
}
subscribeToTopic($client, $apiKey);
if ($packet = $client->wait("subscribed")) {
echo ("Subscribed to " . json_encode($packet->data));
};
while (($packet = $client->wait("reply-message")) && !$disconnect) {
print_r($packet->data);
};
if ($packet = $client->wait("unsubscribed")) {
$client->disconnect();
echo "Unsubscribed every consumer\n";
};