Email through the API
Send and reply to emails from your connected mailbox. Read the thread as a conversation.
Before you start: a Gmail, Outlook, or your-own-domain mailbox connected in Platica, under Integrations. Mailboxes are finished there, in their wizard; through the API you can request the connection and send the link to someone on your team.
Find the mailbox
Which email mailboxes do I have connected?
Your assistant uses
list_channels.curl https://api.platic.ai/v1/channels \ -H "Authorization: Bearer $PLATIC_API_KEY"import { Platic } from "platic-sdk"; const platic = new Platic({ apiKey: process.env.PLATIC_API_KEY! }); const channels = await platic.channels.list();Each mailbox is a channel with
platform: "email"and anidwith theem-prefix: save it inCHANNEL_ID.Write an email
Without a conversation, the email starts a new thread. If you send an agent, it answers when Ana replies.
Send an email to ana@example.com from sales@ with the subject "Your quote" and have the Sales agent handle her reply.
Your assistant uses
send_email.curl https://api.platic.ai/v1/messages/email \ -H "Authorization: Bearer $PLATIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "channelId": "'$CHANNEL_ID'", "to": "ana@example.com", "subject": "Your quote", "text": "Hi Ana, here is your quote.", "agentId": "'$AGENT_ID'" }'const channelId = process.env.CHANNEL_ID!; const sent = await platic.messages.sendEmail({ channelId, to: "ana@example.com", subject: "Your quote", text: "Hi Ana, here is your quote.", agentId: process.env.AGENT_ID });Save
data.conversationIdinCONVERSATION_IDto continue the same thread. If Ana does not exist as a contact, she is created. To send HTML or attachments, see send an email.Reply in the same thread
With the conversation, the email goes out as a reply, with the same subject.
Reply to Ana that I will send it as a PDF.
Your assistant uses
send_email.curl https://api.platic.ai/v1/messages/email \ -H "Authorization: Bearer $PLATIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "channelId": "'$CHANNEL_ID'", "conversationId": "'$CONVERSATION_ID'", "text": "Sure, I will send it as a PDF." }'await platic.messages.sendEmail({ channelId, conversationId: sent.conversationId, text: "Sure, I will send it as a PDF." });Read the thread
What did Ana reply?
Your assistant uses
list_conversation_messages_v2.curl "https://api.platic.ai/v2/conversations/$CONVERSATION_ID/messages?fields=createdAt,sender,content,email" \ -H "Authorization: Bearer $PLATIC_API_KEY"const thread = await platic.conversations.messages.list(sent.conversationId, { fields: ["createdAt", "sender", "content", "email"], });Each message has
contentin plain text and, when you ask for it infields, anemailblock with the subject, who sent it, the recipients and the attachments. The conversation has its ownemail, with the subject and the mailbox. See the conversation's messages. The HTML body is in the V1 read: get a conversation (V1).
Your team sees the same threads in Platica's inbox.
Each thread is a conversation
When you connect a mailbox, each email thread is a conversation, with its contact and its agent. A contact can have several threads in the same mailbox: one per subject.
- To list only email, use
platform=emailin list conversations. - To find a contact by their email, use get a contact with the email instead of the id.
New emails by webhook
Emails that arrive and emails that go out trigger message.created, like any other message. data.message.email has the email block and data.conversation.email the thread's. See payloads.
Replying with send message
POST /v1/messages also replies to a thread, with text only. To start a thread, for HTML, or for attachments, use POST /v1/messages/email.
Limits
- No copy (
cc) or blind copy (bcc). - Up to 10 attachments per email. For now, each attachment's URL has to be a file stored in Platica.
- No email campaigns.
- An agent answers emails, but does not start threads on its own.
- Mailboxes on your own domain write and reply the same as Gmail and Outlook. They are connected in Platica, under Email.
Connecting a channel with type gmail, outlook, or email creates a pending connection: authorizeIn opens the mailbox wizard in Platica, and the connection becomes connected when someone on your team finishes it. That connection has no shareable link (shareUrl).