# Messages
Messages are the most convenient way for Users to reach out and discuss.
Simply create a message as follows, optionally referencing an Asset:
await stelace.messages.create({
topicId: 'ast_2l7fQps1I3a1gJYz2I3a', // Asset id
content: 'Hi, how are you?',
senderId: 'usr_xC3ZlGs1Jo71gb2G0Jo7',
receiverId: 'usr_WHlfQps1I3a1gJYz2I3a'
})
When omitted, senderId
is automatically set to authenticated User id.
When the receiver gets the message, it can be marked as read:
await stelace.messages.update('msg_Vuz9KRs10NK1gAHrp0NK', {
read: true
})
# Conversation
Stelace introduces the concept of conversation to group messages belonging to the same discussion.
A conversationId
is automatically assigned to a message when it isn’t provided, so you can reuse it to group a new message with previous ones.
await stelace.messages.create({
topicId: 'ast_2l7fQps1I3a1gJYz2I3a', // Asset id
content: 'Fine, and you?',
senderId: 'usr_WHlfQps1I3a1gJYz2I3a',
receiverId: 'usr_xC3ZlGs1Jo71gb2G0Jo7',
conversationId: 'conv_4FqUqs1zln1h9gZhzln' // Conversation id from the previous message
})
# List messages
You can get messages sent by or to a specific user with:
await stelace.messages.list({
receiverId: 'usr_WHlfQps1I3a1gJYz2I3a'
})
curl -G https://api.stelace.com/messages \
-u seck_test_rylx3ebUg0bNs1HkJKlqNHkI: \
-d senderId="usr_xC3ZlGs1Jo71gb2G0Jo7"
Retrieving all messages belonging to the same conversation is as simple as:
await stelace.messages.list({
conversationId: 'conv_4FqUqs1zln1h9gZhzln'
})
← Ratings Transactions →