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, a type no built-in plugin claims. To override a built-in type instead, declare the same messageTypes/messageCategories as the default plugin.
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:
Tips
- External API keys are your responsibility — the map preview above calls the Google Maps Static API with
key=YOUR_API_KEY. Replace it with your own Google Maps API key (an external dependency; not provided by CometChat). - Use
context.publish— to communicate with the rest of the UI, publish UI events rather than reaching into other components directly - 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