💬 Messages
SendMessageTo
Sends a message from one phone number to another. This is the recommended export for most use cases as it auto-resolves the sender's phone IMEI and channel ID.
lua
lua
Returns:
lua
Examples:
lua
Attachment Types:
The attachments parameter accepts a JSON-encoded string containing an array of attachment objects:
- Photo:
[{ photo = "https://example.com/image.jpg" }] - Location:
[{ location = { x = -1037.0, y = -2738.0 } }]
Notes:
- Sender number: Can be non-existent (e.g., payphone, system message). The sender's phone IMEI is automatically resolved if the phone exists, otherwise the message will be sent without an IMEI.
- Recipient number(s): MUST exist and be valid. The function will return
nilif any recipient phone number doesn't exist. - Channel ID is automatically resolved if a conversation already exists between the two numbers
- If no existing channel is found, a new one will be created automatically
- For group messages (multiple recipients), a new channel will always be created
- Returns
nilif the message fails to send (e.g., invalid parameters, recipient doesn't exist, database error)
SendMessage
Advanced export for sending messages with full control over all parameters. Use SendMessageTo for most use cases.
lua
lua
Returns:
lua
Note:
- If
channelIdis provided, the message will be added to that existing channel - If
channelIdisnil, the function will look for an existing channel between the sender and recipient(s) - If no existing channel is found, a new channel will be created automatically
- Returns
nilif the message fails to send