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 theroomID
passed [404]. - Ensures that
uid
corresponds to a record in themembers
field of that record with astatus
ofaccepted
[403]. - If
is_thread
has a value oftrue
, find themessage
being referenced in themessages
field having amessageID
corresponding toreply_to
[404]. - Generates a
messageID
as well as atimestamp
for the current date and time. - If
is_thread
has a value offalse
, generate and save a new object in themessages
field of theroom
usingmessageID
,message
,timestamp
ascreated_on
andmodified_on
,uid
assenderID
,false
foris_deleted
and an empty array forviews
. - Else if
is_thread
has a value oftrue
, generate and save a new object in thethreads
field of theroom
usingmessageID
asthreadID
,message
,reply_to
,timestamp
ascreated_on
andmodified_on
,uid
assenderID
,false
foris_deleted
and an empty array forviews
.