{"_id":"@bp-growth/get-botpress-turn-responses","_rev":"8-e77592a07b3caaddade3ea15b9c24b16","name":"@bp-growth/get-botpress-turn-responses","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.1":{"name":"@bp-growth/get-botpress-turn-responses","version":"1.0.1","keywords":["botpress","chatbot","conversation","api","client"],"author":"","license":"MIT","_id":"@bp-growth/get-botpress-turn-responses@1.0.1","maintainers":[{"name":"bp.patrick","email":"patrick.hamelin@botpress.com"}],"dist":{"shasum":"642e181cefbef23dc70e0ddba712f2a9c72ac3a8","tarball":"https://registry.npmjs.org/@bp-growth/get-botpress-turn-responses/-/get-botpress-turn-responses-1.0.1.tgz","fileCount":8,"integrity":"sha512-2Yh0PJt6Jp0vCXrxO9q1RIUplqocCf5Qh2PweZrP1R5b4jJzmTq/RGNVAD8JaO21mIYrN1XsSeoYVN2VKtiSZA==","signatures":[{"sig":"MEUCIQDc23IypjYf7VlwS/oghXCX6Lf7aLA9xdh2iVRlBZnMvwIgHQjL8rl6UiXq748lQci8ibH22EmL9iVUdZtSZChY8KI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":39232},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=18"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"ef4319f364a6bdad46a126abf0e601b3e34bc4a2","scripts":{"dev":"tsup --watch","lint":"eslint . --ext .ts","test":"vitest run","build":"tsup","format":"prettier --write .","release":"pnpm build && changeset publish","version":"changeset version","changeset":"changeset","test:watch":"vitest","type-check":"tsc --noEmit","prepublishOnly":"pnpm build && pnpm test"},"_npmUser":{"name":"bp.patrick","email":"patrick.hamelin@botpress.com"},"_npmVersion":"10.2.3","description":"Send messages to Botpress bots and get turn-by-turn responses with logs","directories":{},"_nodeVersion":"20.10.0","dependencies":{"@botpress/sdk":"^4.14.0","@botpress/client":"^1.16.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.0.0","tsup":"^8.0.0","husky":"^8.0.0","dotenv":"^17.2.2","eslint":"^8.0.0","vitest":"^1.0.0","prettier":"^3.0.0","@vitest/ui":"^1.0.0","typescript":"^5.0.0","@types/node":"^20.0.0","lint-staged":"^15.0.0","@changesets/cli":"^2.27.0","eslint-config-prettier":"^9.0.0","eslint-plugin-prettier":"^5.0.0","@typescript-eslint/parser":"^6.0.0","@typescript-eslint/eslint-plugin":"^6.0.0"},"_npmOperationalInternal":{"tmp":"tmp/get-botpress-turn-responses_1.0.1_1757301358796_0.6734211040864624","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2025-09-08T03:15:58.674Z","modified":"2025-09-30T17:22:08.527Z","1.0.0":"2025-09-08T03:09:29.301Z","1.0.1":"2025-09-08T03:15:58.976Z"},"license":"MIT","keywords":["botpress","chatbot","conversation","api","client"],"description":"Send messages to Botpress bots and get turn-by-turn responses with logs","maintainers":[{"email":"patrick.hamelin@botpress.com","name":"bp.patrick"},{"email":"nabil.muzafar@botpress.com","name":"nabilbotpress"},{"email":"simonnrisk@gmail.com","name":"simonnrisk"},{"email":"ermek.barmashev@botpress.com","name":"ermekbotpress"},{"email":"maanav.rajesh@botpress.com","name":"maanav_rajesh"}],"readme":"# get-botpress-turn-responses\n\nTest Botpress bots by sending messages and getting turn-by-turn responses with logs.\n\n**Note:** Your bot must have the webchat integration installed.\n\n## Installation\n\n```bash\nnpm install @bp-growth/get-botpress-turn-responses\n```\n\n## Usage\n\n```typescript\nimport { getChatTurnResponses } from '@bp-growth/get-botpress-turn-responses';\n\nconst messages = [\n  { type: 'text', payload: { text: 'Hello' } },\n  { type: 'text', payload: { text: 'How are you?' } }\n];\n\nconst result = await getChatTurnResponses(messages, {\n  botId: 'your-bot-id',\n  token: 'your-token',\n  workspaceId: 'your-workspace-id',\n  delayBetweenMessages: 1000 // Optional\n});\n\nconsole.log(result.messages); // All messages\nconsole.log(result.logs);     // All logs\n```\n\n## API\n\n### getChatTurnResponses(messages, options)\n\nSends messages to a bot and returns responses with logs.\n\n#### Parameters\n\n- `messages`: Array of message objects with `type` and `payload`\n  - Messages use the types from `@botpress/sdk` (`text`, `image`, `audio`, `video`, `file`, etc.)\n- `options`: Configuration object\n  - `botId`: Botpress bot ID (required)\n  - `token`: Botpress API token (required)\n  - `workspaceId`: Botpress workspace ID (required)\n  - `delayBetweenMessages?`: Delay in ms between messages (default: 1000)\n  - `pollInterval?`: Polling interval in ms for logs (default: 500)\n  - `timeout?`: Timeout in ms for turn completion (default: 30000)\n\n#### Returns\n\n- `conversationId`: ID of the created conversation\n- `userId`: ID of the created user\n- `messages`: Array of all messages in the conversation (user and bot)\n- `logs`: Array of all logs from the conversation\n\n### Message Types\n\nThe library supports all message types from `@botpress/sdk`:\n\n```typescript\n// Text message\n{ type: 'text', payload: { text: 'Hello' } }\n\n// Image message\n{ type: 'image', payload: { imageUrl: 'https://example.com/image.jpg' } }\n\n// Audio message\n{ type: 'audio', payload: { audioUrl: 'https://example.com/audio.mp3' } }\n\n// Video message  \n{ type: 'video', payload: { videoUrl: 'https://example.com/video.mp4' } }\n\n// File message\n{ type: 'file', payload: { fileUrl: 'https://example.com/file.pdf' } }\n\n// Card message\n{ \n  type: 'card', \n  payload: { \n    title: 'Card Title',\n    subtitle: 'Card subtitle',\n    imageUrl: 'https://example.com/image.jpg',\n    actions: []\n  } \n}\n\n// Carousel message\n{\n  type: 'carousel',\n  payload: {\n    items: [\n      { title: 'Item 1', subtitle: 'Description', imageUrl: '...' },\n      { title: 'Item 2', subtitle: 'Description', imageUrl: '...' }\n    ]\n  }\n}\n\n// And more...\n```\n\n## Turn Completion Detection\n\nThe library monitors the bot's logs for \"Billed Tokens:\" to determine when a conversation turn is complete. This ensures that all bot responses are received before sending the next message.\n\n## Example\n\n```typescript\nimport { getChatTurnResponses } from '@bp-growth/get-botpress-turn-responses';\n\nasync function testBot() {\n  const messages = [\n    { type: 'text', payload: { text: 'Hello' } },\n    { type: 'text', payload: { text: 'I want to buy a hoodie' } },\n    { type: 'text', payload: { text: \"What's the most expensive one?\" } }\n  ];\n\n  try {\n    const result = await getChatTurnResponses(messages, {\n      botId: process.env.BOTPRESS_BOT_ID!,\n      token: process.env.BOTPRESS_TOKEN!,\n      workspaceId: process.env.BOTPRESS_WORKSPACE_ID!,\n      delayBetweenMessages: 1500\n    });\n\n    // Process user and bot messages\n    result.messages.forEach(msg => {\n      if (msg.userId === result.userId) {\n        console.log('User:', msg.payload);\n      } else {\n        console.log('Bot:', msg.payload);\n      }\n    });\n\n    // Check turn completions in logs\n    const turnCompletions = result.logs.filter(log => \n      log.message.includes('Billed Tokens:')\n    );\n    console.log('Turns completed:', turnCompletions.length);\n\n  } catch (error) {\n    console.error('Error:', error);\n  }\n}\n```\n\n## Development\n\n```bash\n# Install dependencies\npnpm install\n\n# Build the package\npnpm build\n\n# Run in watch mode\npnpm dev\n\n# Run tests\npnpm test\n\n# Run example\npnpm example\n\n# Type checking\npnpm type-check\n\n# Linting\npnpm lint\n\n# Format code\npnpm format\n```\n\n## Requirements\n\n- Node.js >= 18\n- Botpress account with API access\n- Bot ID, Personal Access Token, and Workspace ID from Botpress\n\n## License\n\nMIT","readmeFilename":"README.md"}