The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.
TypeScript b2b-marketplacecomposable-commerceecommerceenterpriseheadless-commercemarketplacemedusamedusajsmulti-vendortypescript
feat(registry): add vendor-chat block with TalkJS integration
vholik4e2d16295563
diff --git a/packages/registry/registry.json b/packages/registry/registry.jsonindex 83ac905e0..b131ccf27 100644--- a/packages/registry/registry.json+++ b/packages/registry/registry.json@@ -854,7 +854,7 @@"path": "requests/api/vendor/requests/product-tags/helpers.ts","type": "registry:api"},-{+ {"path": "requests/api/store/requests/helpers.ts","type": "registry:api"},@@ -963,6 +963,27 @@"api","workflow"]+ },+ {+ "name": "vendor-chat",+ "description": "TalkJS chat integration for vendors. Provides a vendor API endpoint to retrieve seller conversations from TalkJS.",+ "dependencies": [],+ "registryDependencies": [],+ "docs": "## Vendor Chat (TalkJS)\n\nThis block adds a TalkJS chat integration for vendors, exposing a `GET /vendor/talkjs` endpoint that retrieves conversations for the authenticated seller and a Messages page in the vendor portal.\n\n### Environment Variables\n\nAdd the following to your `.env`:\n\n```\nVITE_TALK_JS_APP_ID=your_talkjs_app_id\nTALKJS_SECRET_API_KEY=your_talkjs_secret_api_key\n```\n\n### Vite Configuration\n\nAdd the `__TALK_JS_APP_ID__` define to your vendor portal's `vite.config.ts`:\n\n```ts\nconst TALK_JS_APP_ID = env.VITE_TALK_JS_APP_ID || \"\"\n\nexport default defineConfig({\n // ...\n define: {\n __TALK_JS_APP_ID__: JSON.stringify(TALK_JS_APP_ID),\n },\n})\n```\n\n### Run codegen\n\nAfter installing the block, regenerate SDK types:\n\n```bash\nnpx @mercurjs/cli@canary codegen\n```",+ "files": [+ {+ "path": "vendor-chat/api/vendor/talkjs/route.ts",+ "type": "registry:api"+ },+ {+ "path": "vendor-chat/vendor/pages/messages/page.tsx",+ "type": "registry:vendor"+ }+ ],+ "categories": [+ "api",+ "vendor"+ ]}]}\ No newline at end of filediff --git a/packages/registry/src/vendor-chat/api/vendor/talkjs/route.ts b/packages/registry/src/vendor-chat/api/vendor/talkjs/route.tsnew file mode 100644index 000000000..f0f4f7399--- /dev/null+++ b/packages/registry/src/vendor-chat/api/vendor/talkjs/route.ts@@ -0,0 +1,31 @@+import { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/framework"+import { ContainerRegistrationKeys } from "@medusajs/framework/utils"++export const GET = async (+ req: AuthenticatedMedusaRequest,+ res: MedusaResponse+) => {+ const logger = req.scope.resolve(ContainerRegistrationKeys.LOGGER)+ const { TALKJS_APP_ID, TALKJS_SECRET_API_KEY } = process.env++ try {+ const response = await fetch(+ `https://api.talkjs.com/v1/${TALKJS_APP_ID}/users/${req.auth_context.actor_id}/conversations`,+ {+ headers: {+ Authorization: `Bearer ${TALKJS_SECRET_API_KEY}`,+ },+ }+ )++ if (![200, 404].includes(response.status)) {+ throw new Error(`Response ${response.status}`)+ }++ const { data } = await response.json()+ res.json({ conversations: response.status === 200 ? data : [] })+ } catch (e: any) {+ logger.error(`TalkJS error: ${e.message}`)+ res.status(500).json({ message: "TalkJS error!" })+ }+}diff --git a/packages/registry/src/vendor-chat/vendor/pages/messages/page.tsx b/packages/registry/src/vendor-chat/vendor/pages/messages/page.tsxnew file mode 100644index 000000000..276e164bc--- /dev/null+++ b/packages/registry/src/vendor-chat/vendor/pages/messages/page.tsx@@ -0,0 +1,38 @@+import { Container, Heading, Text } from "@medusajs/ui";+import { ChatBubbleLeftRight } from "@medusajs/icons";+import { Inbox } from "@talkjs/react";+import type { RouteConfig } from "@mercurjs/dashboard-sdk";++declare const __TALK_JS_APP_ID__: string | undefined;++export const config: RouteConfig = {+ label: "Messages",+ icon: ChatBubbleLeftRight,+};++const MessagesPage = () => {+ return (+ <Container className="divide-y p-0 min-h-[700px]">+ <div className="flex items-center justify-between px-6 py-4">+ <div>+ <Heading>Messages</Heading>+ </div>+ </div>++ <div className="px-6 py-4 h-[655px]">+ {__TALK_JS_APP_ID__ ? (+ <Inbox className="h-full" />+ ) : (+ <div className="flex flex-col items-center w-full h-full justify-center">+ <Heading>No TalkJS App ID</Heading>+ <Text className="text-ui-fg-subtle mt-4" size="small">+ Connect TalkJS to manage your messages+ </Text>+ </div>+ )}+ </div>+ </Container>+ );+};++export default MessagesPage;