Link Search Menu Expand Document

Send

/api/v2/message/send

Post

rooms

notifications

jwt


Purpose

To allow a user to send a message in a chat room that he/she is a member of.

Body Content [input]

{
    uid: string,
    roomID: string,
    message: string,
    is_thread: bool,
    reply_to: string
}

Returns if valid [output]

{
    messageID: string,
    error: 0
}

What the API does

  • Finds the record from the rooms collection corresponding to the roomID passed [404].
  • Ensures that uid corresponds to a record in the members field of that record with a status of accepted [403].
  • If is_thread has a value of true, find the message being referenced in the messages field having a messageID corresponding to reply_to [404].
  • Generates a messageID as well as a timestamp for the current date and time.
  • If is_thread has a value of false, generate and save a new object in the messages field of the room using messageID, message, timestamp as created_on and modified_on, uid as senderID, false for is_deleted and an empty array for views.
  • Else if is_thread has a value of true, generate and save a new object in the threads field of the room using messageID as threadID, message, reply_to, timestamp as created_on and modified_on, uid as senderID, false for is_deleted and an empty array for views.