# Bubblegram Docs ## Quick Start Get from zero to a working chat widget in under 5 minutes. 1. **Create an account** Sign up at [dash.bubblegram.co](https://dash.bubblegram.co). 2. **Create a project** Enter a name and your site's domain (e.g. `example.com`). 3. **Connect Telegram** Click **Link Telegram** in your project. One tap adds the bot and links the group. See [Telegram Setup](#telegram-setup). 4. **Embed the script tag** Paste one line of HTML into your site. See [Embed the Widget](#embed-widget). 5. **Done.** The chat bubble appears on your site. Visitors send messages; you reply in Telegram. Replies are delivered back to the widget in real time. --- ## Telegram Setup Bubblegram delivers visitor messages to a Telegram group. Each visitor gets a dedicated topic thread so conversations stay organized. --- ### 1. Create a Telegram group 1. Open Telegram and tap the pencil icon (or "New Message"). 2. Choose **New Group**. 3. Optionally add members (you can add yourself from another account, or a teammate). You can also skip this and create the group alone. 4. Give the group a name, then create it. --- ### 2. Enable Topics (Forum mode) Topics allow each visitor to get their own thread inside the group. Without this, all messages arrive in one mixed stream. **On desktop** 1. Open the group and click **Manage group**. 2. Go to **Topics** and enable it. 3. Set the display to **List**. This makes it easier to scan and manage multiple visitor conversations. **On mobile** 1. Tap the group name at the top to open group info. 2. Tap **Group settings**. 3. Go to **Topics** and enable it. 4. Select **List** as the display style. > **Warning:** **Required.** Topics must be enabled before linking. The bot creates a new topic for each visitor. > **Info:** **Unmute the group.** Telegram mutes groups by default. Open the group, tap the bell icon, and select **Unmute** so you get notified when visitors send messages. [Video: /assets/EnableTopics.mp4](/assets/EnableTopics.mp4) --- ### 3. Add the bot In the dashboard, open your project and click **Link Telegram**. This opens Telegram with the bot pre-selected and admin permissions pre-filled. Confirm. The bot joins, gets admin rights, and links your group automatically. No extra steps. > **Info:** **Token expires in 10 minutes.** If the link expires, go back to the dashboard and click **Link Telegram** again to get a new one. ![Link Telegram button in the Project Builder](/assets/link-to-telegram.png) **Already have the bot in the group?** If the bot was already a member before you started setup, the deep link won't fire. Instead, copy the `/start` command from the dashboard and send it in the group manually: ``` /start YOUR_LINK_TOKEN ``` The bot replies: *"Project linked successfully."* Then promote it to admin. It needs permission to manage topics, post messages, and delete messages. --- ## Embed the Widget The widget loads from a CDN and is initialized with your project's API key. --- ### Script tag Add this to your HTML, just before the closing `` tag: ```html ``` Your API key is shown in the project's **Embed** section in the dashboard, visible after your Telegram group is linked. --- ### Attributes | Attribute | Required | Description | | --- | --- | --- | | `data-key` | **Required** | Your project's public API key. Starts with `pk_live_`. | | `data-api` | **Optional** | API base URL. Defaults to `https://api.bubblegram.co`. | | `data-email` | **Optional** | Pre-fill the visitor's email. Useful on server-rendered pages where the user is already signed in. Skips the email input even when "Require email" is enabled. | --- ### JavaScript API After the script loads, a `Bubblegram` object is available on `window`. You can control the widget programmatically: ```js Bubblegram.open() // open the chat panel Bubblegram.close() // close the chat panel Bubblegram.connect() // reconnect WebSocket (if disconnected) Bubblegram.setEmail('user@example.com') // pre-fill email for signed-in users ``` The widget has no way to detect your app's auth state on its own. Without `data-email` or `setEmail`, every visitor shows up as anonymous in your dashboard, signed in or not. Call `setEmail` yourself once the email is known after client-side auth. For example, in React or Next.js after the session loads: ```js useEffect(() => { if (session?.user?.email) { window.Bubblegram?.setEmail(session.user.email) } }, [session?.user?.email]) ``` If this runs before `widget.js` has finished loading (common in SPAs, since the script tag is `async`), `window.Bubblegram` won't exist yet and the call is silently lost. Use the queue stub shown in the React/Next.js examples below to make it safe to call anytime. Calling `setEmail` with a *different* email than the one already set starts a fresh conversation: the current session is cleared and reinitialized, local message history is wiped, and the WebSocket reconnects, before the new email is saved. The first `setEmail` call for a visitor (no email set yet) doesn't trigger this. Keep this in mind if you call `setEmail` again later, e.g. when a visitor switches accounts, since any messages from the old session won't carry over. On server-rendered pages (PHP, Rails, Django, etc.) where the email is available at render time, use the `data-email` attribute instead: ```html ``` For React, Next.js, or other SPAs, add the script to your root HTML file. In Vite or Create React App, that's `index.html`: ```html ``` In Next.js, use the built-in `Script` component in your `_app.tsx` or root layout. Load the stub with `beforeInteractive` so it exists before any of your components try to call `Bubblegram`: ```jsx