Connecting to Things Solver Workforce Chat API
This tutorial guides you through authenticating and connecting to the Things Solver Workforce chat API using WebSockets. It also demonstrates how to send a message with a base64-encoded image.
1. Authentication: Obtain the API Token
Before connecting to the WebSocket, you need to authenticate using your credentials (username and password) to obtain an access token.
Request:
curl --location 'https://workforce-eu.thingsolver.com/api/latest/auth/login' \
--header 'Content-Type: application/json' \
--data '{"username": "", "password":""}'
Response:
This request will return a JSON response containing a token. Save the token – it will be required in the next step.
2. Connect to WebSocket Chat API
After obtaining the token, connect to the chat WebSocket endpoint using the following URL format:
wss://workforce-eu.thingsolver.com/api/latest/chat-api/agents/{agent_id}/{tenant_id}
Replace {agent_id} and {tenant_id} with the appropriate values for your account.
Important Header:
Sec-WebSocket-Protocol: {your_token}
3. Sending a Message with an Image
To send a message via WebSocket, use the following JSON format. The image must be base64-encoded and included along with the query text.
Example JSON payload:
{
"message": {
"content": [
{ "type": "text", "text": "What's in this image?" },
{ "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,{base64_image}" } }
]
},
"details": {}
}
- Replace {base64_image} with the actual base64-encoded string of your image.
Summary
1. Authenticate and get a token.
2. Connect to the WebSocket using the correct URL and include the token in Sec-WebSocket-Protocol.
3. Send a JSON message with both text and a base64-encoded image.
This setup allows you to interact with the chat agent via image-based queries.
Comments
0 comments
Please sign in to leave a comment.