@bookipi/ai-chat-pubsub
v0.0.9-20260701081231
Published
AI Chat frontend client communication
Readme
@bookipi/ai-chat-pubsub
Overview
This package provides a publish-subscribe (PubSub) communication system that enables seamless communication between Bookipi AI Chat and other Bookipi products.
Installation
For latest release:
npm install @bookipi/ai-chat-pubsubFor alpha release:
npm install @bookipi/ai-chat-pubsub@alphaDevelopment
Testing locally
- Build the Pubsub package
pnpm build- Update your app's package.json by re-pointing @bookipi/ai-chat-pubsub to the path of the Pubsub package
"@bookipi/ai-chat-pubsub": "file:../ai-chat/packages/pubsub",- Install
npm install- Start your app
Publishing
In order to publish a package, you just need to create a tag and push it to the repository. The tag number has no connection to the actual package version nor the version in the package.json. The Code Pipeline gets triggered when it detects a new tag. Just make sure that the tag number is 1 number higher than the previous tag.
For production release:
Pubsub changes need to be merged into the main branch first before we can publish a new production version. Once merged, switch to the main branch and run the following commands.
Make sure to update the actual package version.
git tag package-release-v0.0.1
git push origin package-release-v0.0.1The tag number should be 1 number higher than the previous tag.
e.g., from package-release-v0.0.1 > package-release-v0.0.2
For alpha release:
Pubsub changes need to be merged into the staging branch first before we can publish a new alpha version. Once merged, switch to the staging branch (or the project branch, as long as the commit for the Pubsub changes is there) and run the following commands.
Make sure to update the actual alpha package version.
git tag package-alpha-release-v0.0.1-1
git push origin package-alpha-release-v0.0.1-1The tag number should be 1 number higher than the previous tag.
e.g., from package-alpha-release-v0.0.1 > package-alpha-release-v0.0.2
How to use
Main page
You need to initialize the library on the main page with 2 steps
- Import the library
import { PubSub } from "@bookipi/ai-chat-pubsub";- Start it
const pubsub = PubSub.getInstance();Sub page (within iframe or component)
- Import the library
import { Client, IMessage } from "@bookipi/ai-chat-pubsub";- Define your page/component id
const pageId = "page-id";- Start a new Client instance and register your page Id with pubsub manager
const [client] = useState(() => new Client(pageId)); // Register the client- Listen for messages
client.onMessage((message: IMessage) => {
setMessages((prev) => [...prev, message]);
});- Sending a message
client.sendMessage(targetPageId, event);
// Note: event can be a string or a JSON object