Step 1: Define the Plugin
Create a file that implementsCometChatMessagePlugin:
src/plugins/LocationPlugin.tsx
Step 2: Register the Plugin
Pass your plugin toCometChatProvider:
src/App.tsx
"location" messages.
Step 3: Send a Location Message
Use the CometChat SDK to send a custom message with type"location":
Step 4: Style the Bubble
src/plugins/LocationPlugin.css
Plugin Interface Reference
Plugin Context
Thecontext object passed to every plugin method:
| Field | Type | Description |
|---|---|---|
loggedInUser | CometChat.User | The currently logged-in user |
group | CometChat.Group | undefined | The group (if group chat) |
alignment | "left" | "right" | "center" | Bubble alignment |
theme | "light" | "dark" | Current theme |
getLocalizedString | (key: string) => string | Localization function |
onDeleteMessage | (msg) => void | Delete a message |
onEditMessage | (msg) => void | Enter edit mode |
onReplyMessage | (msg) => void | Set reply-to target |
onThreadClick | (msg) => void | Open thread view |
onReactToMessage | (msg) => void | Open emoji picker |
onMessageInfo | (msg) => void | Open message info panel |
onMarkAsUnread | (msg) => void | Mark as unread |
onFlagMessage | (msg) => void | Open flag/report dialog |
showToast | (text) => void | Show a toast notification |
getTextFormatters | () => Formatter[] | Get text formatters for caption rendering |
publish | (event) => void | Publish a UI event |
Tips
- Lazy-load heavy components — use
React.lazy()+Suspensefor bubble components that import large libraries - Use
context.getLocalizedString— for any user-facing text in options or bubbles - Return
[]fromgetOptions— for system messages that shouldn’t have a context menu - Keep
getLastMessagePreviewshort — max ~100 characters, plain text only (no HTML) - A single plugin can handle multiple types — like the Call Action plugin handles both
audioandvideoin thecallcategory