Skip to main content

Send message to delivery

POST 

/company/delivery/msg/:id

Send a message to a delivery's chat, with the option to attach files.

Objective

Facilitate direct communication between the company and the carrier within the context of a specific delivery.

Use Cases

  • Coordinate loading/unloading details
  • Notify of urgent operational changes
  • Share relevant photos or documents
  • Resolve incidents during transport

Validation Flow

flowchart TD
A[Receive Message] --> B{Has Message Text?}
B -->|No/Empty| C[400 NOT_MESSAGE]
B -->|Yes| D{Delivery is Active?}
D -->|No| E[403 NOT_ALLOWED]
D -->|Yes| F{User Authenticated?}
F -->|No| G[404 USER_NOT_FOUND]
F -->|Yes| H[Create Message Object]
H --> I{Has Files?}
I -->|Yes| J[Add S3 Keys to Message]
I -->|No| K[Continue]
J --> K
K --> L[Push to messages Array]
L --> M[Save Delivery]
M -->|Error| N[503 Error]
M -->|Success| O[Return All Messages DESC]

Notes

  • The {id} parameter can be service_code or MongoDB _id
  • Accepts up to 6 files (multipart/form-data)
  • Files are saved in S3 with the S3 key
  • Only active deliveries can receive messages (isActive check)
  • Returns all messages sorted by createdAt DESC
  • Files are returned with the full path /images?file=

Request

Responses

Message sent successfully