Click to expand
This is a simple chat library for DynamoDB. It is designed to be used with the AWS SDK for PHP. The package follows a single database design for DynamoDB. You can create a Chat application for your multiple entities.
$conversation = Chat::conversation()
->setAttributes([
'Subject' => 'Group 1',
'Description' => 'My description',
])
->create();
$conversation = Chat::conversation()
->setParticipants(['johnID', 'janeID'])
->setIsDirect(true)
->create();
Note: You will not be able to add additional participants to a direct conversation. Additionally, you can't remove a participant from a direct conversation.
You may want to get a direct conversation between two users. This is useful if you want to send a message to a user, but you don't know if they have a conversation with you already.
$conversation = Chat::conversation()
->getDirectConversation($participant1Id, $participant2Id);
You can add participants to a conversation at any time. However, they will not be able to see messages sent before they were added.
Chat::addParticipants($conversationId, [
'jamesID',
'janeID',
'johnID'
]);
You can remove participants from a conversation at any time. However, they will still be able to see messages sent before they were removed. Otherwise, they will not be able to see any new messages or send messages.
Chat::deleteParticipants(
$conversationId,
['user1', 'user2']
);
$updated = Chat::conversation($conversationId)
->setAttributes([
'Subject' => $newSubject,
'Description' => $description,
// ... unchanged data
])
->update();
Chat::messaging($conversationId)
->message($senderId, 'Hello')
->send();
You can send a message with additional details. This is useful if you want to send a message with a link to a resource, or a file.
$data = [
'images' => [
[
'file_name' => 'post_image.jpg',
'file_url' => 'http://example.com/post_img.jpg',
],
[
'file_name' => 'post_image2.jpg',
'file_url' => 'http://example.com/post_img2.jpg',
],
]
];
$message = Chat::messaging($conversationId)
->message($senderId, 'Hello', $data)
->send();
Deleting a message will remove it from the conversation for the specified user. The message will still be visible to other participants.
Chat::messaging($conversationId, $messageId)
->delete($recipientOwnerId);
Marking a message as read will remove the unread indicator for the specified user. The message will still be visible to other participants.
Chat::messaging($conversationId, $messageId)
->markAsRead($recipientOrOwnerId);
Chat::messaging($conversationId, $messageId)
->react('THUMBS_UP', $participantId);
Chat::messaging($conversationId, $messageId)
->unreact('THUMBS_UP', $participantId);
[] Reactions - like, dislike, laugh, etc
Click to expand
Entity | PK | SK |
---|---|---|
Conversation | CONVERSATION#{ID} | CONVERSATION#{ID} |
Participant | CONVERSATION#{ID} | PARTICIPANT#{ID} |
Message | CONVERSATION#{ID} | MSG#{ID} |
Entity | GSI1PK | GSI1SK |
---|---|---|
Conversation | ||
Participant | PARTICIPANT#{ID} | CONVERSATION#{ID} |
Message | CONVERSATION#{ID} | MSG#{ID} |
Entity | GSI2PK | GSI2SK |
---|---|---|
Conversation | ||
Participant | ||
Message | PARTICIPANT#{senderId} | PARTICIPANT#{recipientId} |