@builderbot/cli 1.3.15-alpha.17 → 1.3.15-alpha.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,18 @@ export interface ValueLabel {
12
12
  value: string;
13
13
  label: string;
14
14
  }
15
+ export interface TemplateCombination {
16
+ provider: string;
17
+ language: string;
18
+ database: string;
19
+ }
20
+ export interface TemplateValidationResult {
21
+ pass: boolean;
22
+ message: string;
23
+ }
15
24
  export declare const PROVIDER_LIST: Provider[];
16
25
  export declare const PROVIDER_DATA: ValueLabel[];
26
+ export type ProviderData = ValueLabel;
17
27
  export declare const AVAILABLE_LANGUAGES: ValueLabel[];
28
+ export declare const validateTemplateCombination: ({ provider, language, database, }: TemplateCombination) => TemplateValidationResult;
18
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/configuration/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,mBAAmB;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,MAAM,QAAQ,GAAG,gBAAgB,GAAG,mBAAmB,CAAA;AAE7D,MAAM,WAAW,UAAU;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CAChB;AAED,eAAO,MAAM,aAAa,EAAE,QAAQ,EAanC,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,UAAU,EAMrC,CAAA;AAED,eAAO,MAAM,mBAAmB,EAAE,UAAU,EAG3C,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/configuration/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,mBAAmB;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,MAAM,QAAQ,GAAG,gBAAgB,GAAG,mBAAmB,CAAA;AAE7D,MAAM,WAAW,UAAU;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,mBAAmB;IAChC,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,wBAAwB;IACrC,IAAI,EAAE,OAAO,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;CAClB;AAED,eAAO,MAAM,aAAa,EAAE,QAAQ,EAcnC,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,UAAU,EAMrC,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,UAAU,CAAA;AAErC,eAAO,MAAM,mBAAmB,EAAE,UAAU,EAG3C,CAAA;AAMD,eAAO,MAAM,2BAA2B,GAAI,mCAIzC,mBAAmB,KAAG,wBAqBxB,CAAA"}
package/dist/index.cjs CHANGED
@@ -287,6 +287,7 @@ const PROVIDER_LIST = [
287
287
  { value: 'meta', label: 'Meta' },
288
288
  { value: 'facebook-messenger', label: 'Facebook Messenger' },
289
289
  { value: 'instagram', label: 'Instagram' },
290
+ { value: 'gupshup', label: 'Gupshup' },
290
291
  { value: 'gohighlevel', label: 'GoHighLevel' },
291
292
  { value: 'email', label: 'Email', hint: 'IMAP/SMTP' },
292
293
  ];
@@ -301,6 +302,23 @@ const AVAILABLE_LANGUAGES = [
301
302
  { value: 'ts', label: 'TypeScript' },
302
303
  { value: 'js', label: 'JavaScript' },
303
304
  ];
305
+ const GUPSHUP_SUPPORTED_TEMPLATE_COMBINATIONS = [
306
+ { provider: 'gupshup', language: 'ts', database: 'memory' },
307
+ ];
308
+ const validateTemplateCombination = ({ provider, language, database, }) => {
309
+ if (provider !== 'gupshup') {
310
+ return { pass: true, message: '' };
311
+ }
312
+ const pass = GUPSHUP_SUPPORTED_TEMPLATE_COMBINATIONS.some((combo) => combo.provider === provider && combo.language === language && combo.database === database);
313
+ if (pass) {
314
+ return { pass, message: '' };
315
+ }
316
+ const supportedCombinations = GUPSHUP_SUPPORTED_TEMPLATE_COMBINATIONS.map((combo) => `--provider=${combo.provider} --language=${combo.language} --database=${combo.database}`).join('\n');
317
+ return {
318
+ pass,
319
+ message: `Unsupported template combination for provider ${provider}.\nSupported combinations:\n${supportedCombinations}`,
320
+ };
321
+ };
304
322
 
305
323
  var fs = {};
306
324
 
@@ -9519,6 +9537,14 @@ const createApp = async (templateName) => {
9519
9537
  await promises.rename(require$$1.join(pathTemplate, '_gitignore'), require$$1.join(pathTemplate, '.gitignore'));
9520
9538
  return pathTemplate;
9521
9539
  };
9540
+ const validateTemplateSupportOrExit = (provider, language, database) => {
9541
+ const validation = validateTemplateCombination({ provider, language, database });
9542
+ if (validation.pass) {
9543
+ return;
9544
+ }
9545
+ xe(validation.message);
9546
+ process.exit(0);
9547
+ };
9522
9548
  const startInteractive = async (version) => {
9523
9549
  try {
9524
9550
  const stepContinue = await ye({
@@ -9556,6 +9582,7 @@ const startInteractive = async (version) => {
9556
9582
  xe('Operation canceled');
9557
9583
  return process.exit(0);
9558
9584
  }
9585
+ validateTemplateSupportOrExit(stepProvider, stepLanguage, stepDatabase);
9559
9586
  await createBot({
9560
9587
  stepLanguage: stepLanguage,
9561
9588
  stepProvider: stepProvider,
@@ -9631,6 +9658,7 @@ function validateArgs(args) {
9631
9658
  xe(`Invalid language: ${args['language']}`);
9632
9659
  process.exit(0);
9633
9660
  }
9661
+ validateTemplateSupportOrExit(args['provider'], args['language'], args['database']);
9634
9662
  }
9635
9663
  const logError = async (e) => {
9636
9664
  console.log(e);
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interactive/index.ts"],"names":[],"mappings":"AAgQA,QAAA,MAAM,KAAK,QAAa,OAAO,CAAC,IAAI,CAanC,CAAA;AAED,OAAO,EAAE,KAAK,EAAE,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interactive/index.ts"],"names":[],"mappings":"AA8QA,QAAA,MAAM,KAAK,QAAa,OAAO,CAAC,IAAI,CAanC,CAAA;AAED,OAAO,EAAE,KAAK,EAAE,CAAA"}
@@ -0,0 +1,16 @@
1
+ dist/*
2
+ node_modules
3
+ .env
4
+ .pnpm-store
5
+ *_sessions
6
+ *tokens
7
+ .wwebjs*
8
+
9
+ .git
10
+ .gitignore
11
+ Dockerfile*
12
+ npm-debug.log*
13
+ pnpm-debug.log*
14
+ tests
15
+ docs
16
+ *.md
@@ -0,0 +1,40 @@
1
+ # Image size ~ 400MB
2
+ FROM node:21-alpine3.18 as builder
3
+
4
+ WORKDIR /app
5
+
6
+ RUN corepack enable && corepack prepare pnpm@latest --activate
7
+ ENV PNPM_HOME=/usr/local/bin
8
+
9
+ COPY . .
10
+
11
+ COPY package*.json *-lock.yaml ./
12
+
13
+ RUN apk add --no-cache --virtual .gyp \
14
+ python3 \
15
+ make \
16
+ g++ \
17
+ && apk add --no-cache git \
18
+ && pnpm install && pnpm run build \
19
+ && apk del .gyp
20
+
21
+ FROM node:21-alpine3.18 as deploy
22
+
23
+ WORKDIR /app
24
+
25
+ ARG PORT
26
+ ENV PORT $PORT
27
+ EXPOSE $PORT
28
+
29
+ COPY --from=builder /app/assets ./assets
30
+ COPY --from=builder /app/dist ./dist
31
+ COPY --from=builder /app/*.json /app/*-lock.yaml ./
32
+
33
+ RUN corepack enable && corepack prepare pnpm@latest --activate
34
+ ENV PNPM_HOME=/usr/local/bin
35
+
36
+ RUN npm cache clean --force && pnpm install --production --ignore-scripts \
37
+ && addgroup -g 1001 -S nodejs && adduser -S -u 1001 nodejs \
38
+ && rm -rf $PNPM_HOME/.npm $PNPM_HOME/.node-gyp
39
+
40
+ CMD ["npm", "start"]
@@ -0,0 +1,44 @@
1
+ <p align="center">
2
+ <a href="https://builderbot.app/">
3
+ <picture>
4
+ <img src="https://builderbot.app/assets/thumbnail-vector.png" height="80">
5
+ </picture>
6
+ <h2 align="center">BuilderBot</h2>
7
+ </a>
8
+ </p>
9
+
10
+
11
+
12
+ <p align="center">
13
+ <a aria-label="NPM version" href="https://www.npmjs.com/package/@builderbot/bot">
14
+ <img alt="" src="https://img.shields.io/npm/v/@builderbot/bot?color=%2300c200&label=%40bot-whatsapp">
15
+ </a>
16
+ <a aria-label="Join the community on GitHub" href="https://link.codigoencasa.com/DISCORD">
17
+ <img alt="" src="https://img.shields.io/discord/915193197645402142?logo=discord">
18
+ </a>
19
+ </p>
20
+
21
+
22
+ ## Getting Started
23
+
24
+ With this library, you can build automated conversation flows agnostic to the WhatsApp provider, set up automated responses for frequently asked questions, receive and respond to messages automatically, and track interactions with customers. Additionally, you can easily set up triggers to expand functionalities limitlessly.
25
+
26
+ ```
27
+ npm create builderbot@latest
28
+ ```
29
+
30
+
31
+ ## Documentation
32
+
33
+ Visit [builderbot](https://builderbot.app/) to view the full documentation.
34
+
35
+
36
+ ## Official Course
37
+
38
+ If you want to discover all the functions and features offered by the library you can take the course.
39
+ [View Course](https://app.codigoencasa.com/courses/builderbot?refCode=LEIFER)
40
+
41
+
42
+ ## Contact Us
43
+ - [💻 Discord](https://link.codigoencasa.com/DISCORD)
44
+ - [👌 𝕏 (Twitter)](https://twitter.com/leifermendez)
@@ -0,0 +1,10 @@
1
+ dist/*
2
+ node_modules
3
+ .env
4
+ .pnpm-store
5
+ *_sessions
6
+ *tokens
7
+ .wwebjs*
8
+
9
+ *.log
10
+ *qr.png
@@ -0,0 +1,25 @@
1
+ import tseslint from 'typescript-eslint'
2
+ import builderbot from 'eslint-plugin-builderbot'
3
+
4
+ export default [
5
+ {
6
+ ignores: ['dist/**', 'node_modules/**', 'rollup.config.js'],
7
+ },
8
+ ...tseslint.configs.recommended,
9
+ {
10
+ plugins: {
11
+ builderbot,
12
+ },
13
+ languageOptions: {
14
+ ecmaVersion: 'latest',
15
+ sourceType: 'module',
16
+ },
17
+ rules: {
18
+ ...builderbot.configs.recommended.rules,
19
+ '@typescript-eslint/no-explicit-any': 'off',
20
+ '@typescript-eslint/no-unused-vars': 'off',
21
+ '@typescript-eslint/ban-ts-comment': 'off',
22
+ 'no-unsafe-optional-chaining': 'off',
23
+ },
24
+ },
25
+ ]
@@ -0,0 +1,12 @@
1
+ {
2
+ "watch": ["src"],
3
+ "ext": "ts",
4
+ "ignore": [
5
+ "**/*.test.ts",
6
+ "**/*.spec.ts"
7
+ ],
8
+ "delay": "3",
9
+ "execMap": {
10
+ "ts": "tsx"
11
+ }
12
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "base-bailey-json",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/app.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "start": "node ./dist/app.js",
9
+ "lint": "eslint . --no-ignore",
10
+ "dev": "npm run lint && nodemon --signal SIGKILL ./src/app.ts",
11
+ "build": "npx rollup -c"
12
+ },
13
+ "keywords": [],
14
+ "dependencies": {
15
+ "@builderbot/bot": "latest",
16
+ "@builderbot/provider-gupshup": "latest"
17
+ },
18
+ "devDependencies": {
19
+ "@types/node": "^25.0.0",
20
+ "typescript-eslint": "^8.0.0",
21
+ "eslint": "^9.0.0",
22
+ "eslint-plugin-builderbot": "latest",
23
+ "rollup": "^4.10.0",
24
+ "nodemon": "^3.1.11",
25
+ "rollup-plugin-typescript2": "^0.36.0",
26
+ "tsx": "^4.7.1",
27
+ "typescript": "^5.4.3"
28
+ },
29
+ "author": "",
30
+ "license": "ISC"
31
+ }
@@ -0,0 +1,13 @@
1
+ import typescript from 'rollup-plugin-typescript2'
2
+
3
+ export default {
4
+ input: 'src/app.ts',
5
+ output: {
6
+ file: 'dist/app.js',
7
+ format: 'esm',
8
+ },
9
+ onwarn: (warning) => {
10
+ if (warning.code === 'UNRESOLVED_IMPORT') return
11
+ },
12
+ plugins: [typescript()],
13
+ }
@@ -0,0 +1,127 @@
1
+ import { join } from 'path'
2
+ import { createBot, createProvider, createFlow, addKeyword, utils } from '@builderbot/bot'
3
+ import { MemoryDB as Database } from '@builderbot/bot'
4
+ import { GupshupProvider as Provider } from '@builderbot/provider-gupshup'
5
+
6
+ const PORT = process.env.PORT ?? 3008
7
+
8
+ const discordFlow = addKeyword<Provider, Database>('doc').addAnswer(
9
+ ['You can see the documentation here', '📄 https://builderbot.app/docs \n', 'Do you want to continue? *yes*'].join(
10
+ '\n'
11
+ ),
12
+ { capture: true },
13
+ async (ctx, { gotoFlow, flowDynamic }) => {
14
+ if (ctx.body.toLocaleLowerCase().includes('yes')) {
15
+ return gotoFlow(registerFlow)
16
+ }
17
+ await flowDynamic('Thanks!')
18
+ return
19
+ }
20
+ )
21
+
22
+ const welcomeFlow = addKeyword<Provider, Database>(['hi', 'hello', 'hola'])
23
+ .addAnswer(`🙌 Hello welcome to this *Chatbot*`)
24
+ .addAnswer(
25
+ [
26
+ 'I share with you the following links of interest about the project',
27
+ '👉 *doc* to view the documentation',
28
+ ].join('\n'),
29
+ { delay: 800, capture: true },
30
+ async (ctx, { fallBack }) => {
31
+ if (!ctx.body.toLocaleLowerCase().includes('doc')) {
32
+ return fallBack('You should type *doc*')
33
+ }
34
+ return
35
+ },
36
+ [discordFlow]
37
+ )
38
+
39
+ const registerFlow = addKeyword<Provider, Database>(utils.setEvent('REGISTER_FLOW'))
40
+ .addAnswer(`What is your name?`, { capture: true }, async (ctx, { state }) => {
41
+ await state.update({ name: ctx.body })
42
+ })
43
+ .addAnswer('What is your age?', { capture: true }, async (ctx, { state }) => {
44
+ await state.update({ age: ctx.body })
45
+ })
46
+ .addAction(async (_, { flowDynamic, state }) => {
47
+ await flowDynamic(`${state.get('name')}, thanks for your information!: Your age: ${state.get('age')}`)
48
+ })
49
+
50
+ const fullSamplesFlow = addKeyword<Provider, Database>(['samples', utils.setEvent('SAMPLES')])
51
+ .addAnswer(`💪 I'll send you a lot files...`)
52
+ .addAnswer(`Send image from Local`, { media: join(process.cwd(), 'assets', 'sample.png') })
53
+ .addAnswer(`Send video from URL`, {
54
+ media: 'https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExYTJ0ZGdjd2syeXAwMjQ4aWdkcW04OWlqcXI3Ynh1ODkwZ25zZWZ1dCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/LCohAb657pSdHv0Q5h/giphy.mp4',
55
+ })
56
+ .addAnswer(`Send audio from URL`, { media: 'https://cdn.freesound.org/previews/728/728142_11861866-lq.mp3' })
57
+ .addAnswer(`Send file from URL`, {
58
+ media: 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',
59
+ })
60
+
61
+ const main = async () => {
62
+ const adapterFlow = createFlow([welcomeFlow, registerFlow, fullSamplesFlow])
63
+ const adapterProvider = createProvider(Provider, {
64
+ apiKey: 'YOUR_API_KEY',
65
+ srcName: 'YOUR_APP_NAME',
66
+ phoneNumber: 'YOUR_SOURCE_NUMBER',
67
+ })
68
+ const adapterDB = new Database()
69
+
70
+ const { handleCtx, httpServer } = await createBot({
71
+ flow: adapterFlow,
72
+ provider: adapterProvider,
73
+ database: adapterDB,
74
+ })
75
+
76
+ adapterProvider.server.post(
77
+ '/v1/messages',
78
+ handleCtx(async (bot, req, res) => {
79
+ const { number, message, urlMedia } = req.body
80
+ await bot.sendMessage(number, message, { media: urlMedia ?? null })
81
+ return res.end('sended')
82
+ })
83
+ )
84
+
85
+ adapterProvider.server.post(
86
+ '/v1/register',
87
+ handleCtx(async (bot, req, res) => {
88
+ const { number, name } = req.body
89
+ await bot.dispatch('REGISTER_FLOW', { from: number, name })
90
+ return res.end('trigger')
91
+ })
92
+ )
93
+
94
+ adapterProvider.server.post(
95
+ '/v1/samples',
96
+ handleCtx(async (bot, req, res) => {
97
+ const { number, name } = req.body
98
+ await bot.dispatch('SAMPLES', { from: number, name })
99
+ return res.end('trigger')
100
+ })
101
+ )
102
+
103
+ adapterProvider.server.post(
104
+ '/v1/blacklist',
105
+ handleCtx(async (bot, req, res) => {
106
+ const { number, intent } = req.body
107
+ if (intent === 'remove') bot.blacklist.remove(number)
108
+ if (intent === 'add') bot.blacklist.add(number)
109
+
110
+ res.writeHead(200, { 'Content-Type': 'application/json' })
111
+ return res.end(JSON.stringify({ status: 'ok', number, intent }))
112
+ })
113
+ )
114
+
115
+ adapterProvider.server.get(
116
+ '/v1/blacklist/list',
117
+ handleCtx(async (bot, req, res) => {
118
+ const blacklist = bot.blacklist.getList()
119
+ res.writeHead(200, { 'Content-Type': 'application/json' })
120
+ return res.end(JSON.stringify({ status: 'ok', blacklist }))
121
+ })
122
+ )
123
+
124
+ httpServer(+PORT)
125
+ }
126
+
127
+ main()
@@ -0,0 +1,34 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ES2022",
5
+ "declaration": false,
6
+ "declarationMap": false,
7
+ "moduleResolution": "node",
8
+ "removeComments": true,
9
+ "emitDecoratorMetadata": true,
10
+ "experimentalDecorators": true,
11
+ "allowSyntheticDefaultImports": true,
12
+ "sourceMap": false,
13
+ "outDir": "./dist",
14
+ "baseUrl": "./",
15
+ "rootDir": "./",
16
+ "incremental": true,
17
+ "skipLibCheck": true,
18
+ "paths": {
19
+ "~/*": ["./src/*"]
20
+ }
21
+ },
22
+ "include": [
23
+ "**/*.js",
24
+ "**/*.ts"
25
+ ],
26
+ "exclude": [
27
+ "node_modules",
28
+ "dist",
29
+ "**/*.test.ts",
30
+ "**/*.spec.ts",
31
+ "**e2e**",
32
+ "**mock**"
33
+ ]
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builderbot/cli",
3
- "version": "1.3.15-alpha.17",
3
+ "version": "1.3.15-alpha.18",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs",
6
6
  "types": "dist/index.d.ts",
@@ -41,5 +41,5 @@
41
41
  "type": "git",
42
42
  "url": "https://github.com/codigoencasa/bot-whatsapp/tree/main/packages/cli"
43
43
  },
44
- "gitHead": "3a191e56045d5785299bfe984da445424e18d29d"
44
+ "gitHead": "b9d6c39d13049d0a2249609417a82dd1f4c20ccf"
45
45
  }