Send message
Post a message to one of your community's channels as an existing member, with text, image links or both.
- Method
- POST
- Path
https://api.returning.ai / v1/ messages/ send - Permission
- sendMessage
- Retries
- Not idempotent; check Get Messages before retrying
When to use this
- Your system posts market updates or announcements into a community channel.
- A bot or support account answers in a channel on your team's behalf.
- You want to share a chart or image in a channel from a public image URL.
Authentication#
- Header
Authorization: Bearer <API_KEY>- Permission
- sendMessageShown in the dashboard as “Send Messages”
Use a Community API key with sendMessage, and keep it on your server. The key decides the community, so never send a community ID. A personal user API key with its own send permission also works; then the message is posted as the key's owner and the channel's posting rules apply.
Behaviour#
The message appears straight away for everyone in the channel, posted as sender. With a Community API key the channel's posting rules aren't checked, so you can post as any member in any of your community's channels; pick sender with care. The sender earns the usual XP and message counts for a message, members named in @ mentions are mentioned, and your community's message webhooks fire. @all mentions every member.
A text that contains a link is handled as an attachment, not as text. When the whole message is one URL, that file is fetched and posted as an attachment with no text. Any other text with a link fails with 400 Error processing attachments. To share a picture with a caption, put the caption in message and the picture in images.
Images in images are copied to Returning.AI storage before posting. More than 10 images are posted as several messages, the first straight away and the rest just after the response.
Request#
Headers#
Body#
RuleChannel ID
Eg"66f000000000000000000a11"
RuleUsername or email of a member
Eg"support@example.com"
@username, or use @{name} when the username has other characters.RuleRequired unless you send images
Eg"The gold webinar starts in 15 minutes."
RuleRequired unless you send message
Eg["https://cdn.example.com/charts/xauusd.png"]
RuleTopic ID in that channel
curl --request POST \
--url https://api.returning.ai/v1/messages/send \
--header 'Authorization: Bearer <API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
"channelId": "66f000000000000000000a11",
"sender": "support@example.com",
"message": "The gold webinar starts in 15 minutes."
}'
Response#
A 200 means the message was posted. The response has no message ID; read the channel with Get Messages to find it.
{
"status": "success",
"message": "Message sent successfully"
}
Errors#
Validation errors use meta, message, detail and solution, with detail naming the field. Every other error has message, sometimes with status or detail. None has a machine-readable code, so branch on the HTTP status and read message.
Fix the request03
channelId, neither message nor images, or an ID that isn't 24 hex characters (detail names the field). Sender field is required means you used a Community API key without sender. Error processing attachments means an image URL couldn't be fetched, or the text contains a link (see Behaviour). Nothing was posted.Invalid token), unknown (Invalid API key) or expired, or it lacks sendMessage (Your API key does not have permission to access this action). Add the permission in Settings > Integration > API Keys.sender names someone other than the key's owner, or the recipient isn't in the direct-message channel. Nothing was posted.Fix the data01
message says which: Channel not found (check channelId with List integration channels), User not found (no member has that sender), Recipient not found, or Forum topic not found or does not belong to this channel. Nothing was posted.Retry with backoff01
Authentication failed). The message may already be posted, so check Get Messages before you retry.{
"meta": {
"status": "error",
"statusCode": 400
},
"message": "Send Message Validation validation error.",
"detail": {
"channelId": "Channel ID must be a valid ObjectId"
},
"solution": "Check your body in request and try again"
}