Talk to your agent
Add an agent to a screen in your product. Your interface sends the message to your backend, which uses the Chat API to get the reply.
Use conversationId to continue the thread and read its history. To send and receive WhatsApp messages or email from your system, follow Use channels through the API.
Before you start
You need a published agent with its id in AGENT_ID and your Platica API key in the backend. Keep the key on the server.
In the platform: Start a chat.
Send the first message
Specify the agent, the message and the person sending it. The same call returns the agent's reply. (Send a message to the agent)
curl https://api.platic.ai/v1/chat \ -H "Authorization: Bearer $PLATIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "agentId": "'$AGENT_ID'", "message": "Which plan fits a team of 25 people?", "client": { "id": "customer_123", "name": "Ana" } }'import { Platic } from "platic-sdk"; const platic = new Platic({ apiKey: process.env.PLATIC_API_KEY! }); const turn = await platic.chat.send({ agentId: process.env.AGENT_ID!, message: "Which plan fits a team of 25 people?", client: { id: "customer_123", name: "Ana" }, }); for (const reply of turn.messages) console.log(reply.content);Ask the Sales agent which plan fits a team of 25 people.
Tool:
send_chat_message.The agent's reply is in
messages. SaveconversationIdinCONVERSATION_IDto continue the thread andidinCHAT_IDto read its history.Identify the person in
clientusing the id from your system. Keep that id in future calls. If you omitclient, the chat belongs to the key's owner.Follow the conversation
Include
conversationIdto continue the thread. If you omit it, another thread is created.To retain information about the person across different threads, enable memory and use the same
client.id.curl https://api.platic.ai/v1/chat \ -H "Authorization: Bearer $PLATIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "conversationId": "'$CONVERSATION_ID'", "message": "We also need WhatsApp." }'const next = await platic.chat.send({ conversationId: turn.conversationId, message: "We also need WhatsApp.", });Tell it we also need WhatsApp.
Tool:
send_chat_messagewith the same conversation.The call waits for the agent to finish, including its tools. If you lose the response, read the conversation before resending the message: repeating it can generate another reply.
Read the history
It returns the full conversation, with the person's messages and the agent's in order. (Get a chat)
curl https://api.platic.ai/v1/chat/$CHAT_ID \ -H "Authorization: Bearer $PLATIC_API_KEY"const chat = await platic.chat.get(turn.id); for (const message of chat.messages) console.log(message.role, message.content);Show me the full conversation with the Sales agent.
Tool:
get_chat. To find an earlier conversation it useslist_chats.In each message,
rolesays who spoke:useris the person andassistantis the agent.
Check it worked
Read the reply in messages and check that the history keeps the person's and agent's messages in order. Your team can also read or handle the conversation from the Platica inbox.
Next steps
- Put it on a channel so it answers Messenger or Instagram.
- Email by API: write and reply to emails from a connected mailbox.
- Embed the web chat to show Platica's chat inside your screen.
- Send a message to the agent: attachments, instructions for a single message and scheduled messages.
- List chats: the conversations of a contact or an agent.
- Conversations: pause the agent, assign, tag, finish or archive what your agent handled.