@wabot-dev/framework 0.1.0-beta.3 → 0.1.0-beta.4

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.
@@ -0,0 +1,49 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { singleton } from '../../injection/index.js';
3
+ import { WhatsApp } from './WhatsApp.js';
4
+ import { WabotEnv } from '../../env/WabotEnv.js';
5
+
6
+ let EnvWhatsAppRepository = class EnvWhatsAppRepository {
7
+ env;
8
+ constructor(env) {
9
+ this.env = env;
10
+ }
11
+ async findBySlug(slug) {
12
+ const whatsApp = this.getFromEnvVars();
13
+ if (whatsApp.getSlug() !== slug) {
14
+ throw new Error(`Not found WhatsApp configuration in env variables for the required slug '${slug}'`);
15
+ }
16
+ return whatsApp;
17
+ }
18
+ async findByBusinessNumber(number) {
19
+ const whatsApp = this.getFromEnvVars();
20
+ if (!whatsApp.getBussinessNumber(number)) {
21
+ throw new Error(`Not found WhatsApp configuration in env variables for the required number '${number}'`);
22
+ }
23
+ return whatsApp;
24
+ }
25
+ getFromEnvVars() {
26
+ const whatsApp = new WhatsApp({
27
+ verifyToken: this.env.requireString('WHATSAPP_HOOK_TOKEN'),
28
+ slug: this.env.requireString('WHATSAPP_HOOK_SLUG'),
29
+ appSecret: this.env.requireString('WHATSAPP_APP_SECRET'),
30
+ businessAccount: {
31
+ id: this.env.requireString('WHATSAPP_ACCOUNT_ID'),
32
+ },
33
+ accessToken: this.env.requireString('WHATSAPP_ACCESS_TOKEN'),
34
+ businessNumbers: [
35
+ {
36
+ id: this.env.requireString('WHATSAPP_BUSINESS_NUMBER_ID'),
37
+ number: this.env.requireString('WHATSAPP_BUSINESS_NUMBER'),
38
+ },
39
+ ],
40
+ });
41
+ return whatsApp;
42
+ }
43
+ };
44
+ EnvWhatsAppRepository = __decorate([
45
+ singleton(),
46
+ __metadata("design:paramtypes", [WabotEnv])
47
+ ], EnvWhatsAppRepository);
48
+
49
+ export { EnvWhatsAppRepository };
@@ -0,0 +1,41 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { Pool } from 'pg';
3
+ import { WhatsApp } from './WhatsApp.js';
4
+ import { singleton } from '../../injection/index.js';
5
+ import { PgCrudRepository } from '../../repository/pg/PgCrudRepository.js';
6
+
7
+ let PgWhatsAppRepository = class PgWhatsAppRepository extends PgCrudRepository {
8
+ constructor(pool) {
9
+ super(pool, {
10
+ table: 'whatsapp',
11
+ constructor: WhatsApp,
12
+ schema: 'wabot',
13
+ });
14
+ }
15
+ async findBySlug(slug) {
16
+ const sql = `
17
+ SELECT ${this.columns}
18
+ FROM ${this.table}
19
+ WHERE data @> $1
20
+ LIMIT 1
21
+ `;
22
+ const items = await this.query(sql, [JSON.stringify({ slug })]);
23
+ return items.at(0) ?? null;
24
+ }
25
+ async findByBusinessNumber(number) {
26
+ const sql = `
27
+ SELECT ${this.columns}
28
+ FROM ${this.table}
29
+ WHERE data->'businessNumbers' @> $1
30
+ LIMIT 1
31
+ `;
32
+ const items = await this.query(sql, [JSON.stringify([{ number }])]);
33
+ return items.at(0) ?? null;
34
+ }
35
+ };
36
+ PgWhatsAppRepository = __decorate([
37
+ singleton(),
38
+ __metadata("design:paramtypes", [Pool])
39
+ ], PgWhatsAppRepository);
40
+
41
+ export { PgWhatsAppRepository };
@@ -6,6 +6,9 @@ class WhatsApp extends Persistent {
6
6
  getVerifyToken() {
7
7
  return this.data.verifyToken;
8
8
  }
9
+ getSlug() {
10
+ return this.data.slug;
11
+ }
9
12
  getBusinessAccount() {
10
13
  return this.data.businessAccount;
11
14
  }
@@ -1,41 +1,10 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { Pool } from 'pg';
3
- import { WhatsApp } from './WhatsApp.js';
4
- import { singleton } from '../../injection/index.js';
5
- import { PgCrudRepository } from '../../repository/pg/PgCrudRepository.js';
6
-
7
- let WhatsAppRepository = class WhatsAppRepository extends PgCrudRepository {
8
- constructor(pool) {
9
- super(pool, {
10
- table: 'whatsapp',
11
- constructor: WhatsApp,
12
- schema: 'wabot',
13
- });
14
- }
15
- async findBySlug(slug) {
16
- const sql = `
17
- SELECT ${this.columns}
18
- FROM ${this.table}
19
- WHERE data @> $1
20
- LIMIT 1
21
- `;
22
- const items = await this.query(sql, [JSON.stringify({ slug })]);
23
- return items.at(0) ?? null;
1
+ class WhatsAppRepository {
2
+ findBySlug(slug) {
3
+ throw new Error('Method not implemented.');
24
4
  }
25
- async findByBusinessNumber(number) {
26
- const sql = `
27
- SELECT ${this.columns}
28
- FROM ${this.table}
29
- WHERE data->'businessNumbers' @> $1
30
- LIMIT 1
31
- `;
32
- const items = await this.query(sql, [JSON.stringify([{ number }])]);
33
- return items.at(0) ?? null;
5
+ findByBusinessNumber(number) {
6
+ throw new Error('Method not implemented.');
34
7
  }
35
- };
36
- WhatsAppRepository = __decorate([
37
- singleton(),
38
- __metadata("design:paramtypes", [Pool])
39
- ], WhatsAppRepository);
8
+ }
40
9
 
41
10
  export { WhatsAppRepository };
@@ -12,6 +12,12 @@ let WabotEnv = class WabotEnv {
12
12
  isProduction() {
13
13
  return this.envType === 'production';
14
14
  }
15
+ requireString(varName) {
16
+ const value = process.env[varName];
17
+ if (!value)
18
+ throw new Error(`Env Variable ${varName} is required`);
19
+ return value;
20
+ }
15
21
  };
16
22
  WabotEnv = __decorate([
17
23
  singleton(),
@@ -4,8 +4,8 @@ import InterceptionOptions from 'tsyringe/dist/typings/types/interceptor-options
4
4
  import { Server } from 'http';
5
5
  import { Express } from 'express';
6
6
  import { Server as Server$1 } from 'socket.io';
7
- import { Pool } from 'pg';
8
7
  import { Socket } from 'socket.io-client';
8
+ import { Pool } from 'pg';
9
9
  import * as tsyringe from 'tsyringe';
10
10
  import { DependencyContainer as DependencyContainer$1 } from 'tsyringe';
11
11
  export { DependencyContainer } from 'tsyringe';
@@ -624,6 +624,7 @@ interface IWhatsAppData extends IPersistentData {
624
624
  }
625
625
  declare class WhatsApp extends Persistent<IWhatsAppData> {
626
626
  getVerifyToken(): string;
627
+ getSlug(): string;
627
628
  getBusinessAccount(): IWhatsAppBusinessAccount;
628
629
  getAppSecret(): string;
629
630
  getBusinessNumbers(): IWhatsAppBusinessNumber[];
@@ -659,66 +660,12 @@ declare abstract class WhatsAppReceiver {
659
660
  private emmitMessage;
660
661
  }
661
662
 
662
- interface ICrudRepository<T> {
663
- find(id: string): Promise<T | null>;
664
- findAll(id: string): Promise<T[]>;
665
- create(item: T): Promise<void>;
666
- update(item: T): Promise<void>;
667
- discard(item: T): Promise<void>;
668
- }
669
-
670
- type IPgRepositoryConfig<P extends Persistent> = {
671
- schema?: string;
672
- table: string;
673
- constructor: IConstructor<P>;
674
- add?: {
675
- columns: {
676
- [column: string]: {
677
- type: string;
678
- value: (item: P) => boolean | number | string | null | Date;
679
- };
680
- };
681
- };
682
- };
683
-
684
- declare class PgRepositoryBase<P extends Persistent> {
685
- protected pool: Pool;
686
- protected config: IPgRepositoryConfig<any>;
687
- private tableIsCreated;
688
- schema: string;
689
- table: string;
690
- columnsList: string[];
691
- columnsAndTypes: string;
692
- columns: string;
693
- vars: string;
694
- updates: string;
695
- addColumns: {
696
- [columns: string]: {
697
- type: string;
698
- value: (item: P) => number | boolean | string | null | Date;
699
- };
700
- };
701
- constructor(pool: Pool, config: IPgRepositoryConfig<any>);
702
- values(item: P): (string | number | boolean | Date | null)[];
703
- protected exec(sql: string, values: any[]): Promise<void>;
704
- protected query(sql: string, values: any[]): Promise<any[]>;
705
- protected connect(): Promise<Pool>;
706
- protected ensureTable(): Promise<void>;
707
- protected ensureColumns(): Promise<void>;
708
- }
709
-
710
- declare class PgCrudRepository<P extends Persistent> extends PgRepositoryBase<P> implements ICrudRepository<P> {
711
- protected readonly config: IPgRepositoryConfig<P>;
712
- constructor(pool: Pool, config: IPgRepositoryConfig<P>);
713
- find(id: string): Promise<P | null>;
714
- findAll(): Promise<P[]>;
715
- create(item: P): Promise<void>;
716
- update(item: P): Promise<void>;
717
- discard(item: P): Promise<void>;
663
+ interface IWhatsAppRepository {
664
+ findBySlug(slug: string): Promise<WhatsApp | null>;
665
+ findByBusinessNumber(number: string): Promise<WhatsApp | null>;
718
666
  }
719
667
 
720
- declare class WhatsAppRepository extends PgCrudRepository<WhatsApp> {
721
- constructor(pool: Pool);
668
+ declare class WhatsAppRepository implements IWhatsAppRepository {
722
669
  findBySlug(slug: string): Promise<WhatsApp | null>;
723
670
  findByBusinessNumber(number: string): Promise<WhatsApp | null>;
724
671
  }
@@ -825,6 +772,87 @@ declare class WhatsAppSenderByCloudApi extends WhatsAppSender {
825
772
  handleGetWhatsAppTemplate(request: IGetWhatsAppTemplateRequest): Promise<IWhatsAppTemplate | null>;
826
773
  }
827
774
 
775
+ interface ICrudRepository<T> {
776
+ find(id: string): Promise<T | null>;
777
+ findAll(id: string): Promise<T[]>;
778
+ create(item: T): Promise<void>;
779
+ update(item: T): Promise<void>;
780
+ discard(item: T): Promise<void>;
781
+ }
782
+
783
+ type IPgRepositoryConfig<P extends Persistent> = {
784
+ schema?: string;
785
+ table: string;
786
+ constructor: IConstructor<P>;
787
+ add?: {
788
+ columns: {
789
+ [column: string]: {
790
+ type: string;
791
+ value: (item: P) => boolean | number | string | null | Date;
792
+ };
793
+ };
794
+ };
795
+ };
796
+
797
+ declare class PgRepositoryBase<P extends Persistent> {
798
+ protected pool: Pool;
799
+ protected config: IPgRepositoryConfig<any>;
800
+ private tableIsCreated;
801
+ schema: string;
802
+ table: string;
803
+ columnsList: string[];
804
+ columnsAndTypes: string;
805
+ columns: string;
806
+ vars: string;
807
+ updates: string;
808
+ addColumns: {
809
+ [columns: string]: {
810
+ type: string;
811
+ value: (item: P) => number | boolean | string | null | Date;
812
+ };
813
+ };
814
+ constructor(pool: Pool, config: IPgRepositoryConfig<any>);
815
+ values(item: P): (string | number | boolean | Date | null)[];
816
+ protected exec(sql: string, values: any[]): Promise<void>;
817
+ protected query(sql: string, values: any[]): Promise<any[]>;
818
+ protected connect(): Promise<Pool>;
819
+ protected ensureTable(): Promise<void>;
820
+ protected ensureColumns(): Promise<void>;
821
+ }
822
+
823
+ declare class PgCrudRepository<P extends Persistent> extends PgRepositoryBase<P> implements ICrudRepository<P> {
824
+ protected readonly config: IPgRepositoryConfig<P>;
825
+ constructor(pool: Pool, config: IPgRepositoryConfig<P>);
826
+ find(id: string): Promise<P | null>;
827
+ findAll(): Promise<P[]>;
828
+ create(item: P): Promise<void>;
829
+ update(item: P): Promise<void>;
830
+ discard(item: P): Promise<void>;
831
+ }
832
+
833
+ declare class PgWhatsAppRepository extends PgCrudRepository<WhatsApp> implements IWhatsAppRepository {
834
+ constructor(pool: Pool);
835
+ findBySlug(slug: string): Promise<WhatsApp | null>;
836
+ findByBusinessNumber(number: string): Promise<WhatsApp | null>;
837
+ }
838
+
839
+ type IWabotEnvType = 'development' | 'staging' | 'testing' | 'production';
840
+ declare class WabotEnv {
841
+ private envType;
842
+ constructor();
843
+ isDevelopment(): boolean;
844
+ isProduction(): boolean;
845
+ requireString(varName: string): string;
846
+ }
847
+
848
+ declare class EnvWhatsAppRepository implements IWhatsAppRepository {
849
+ private env;
850
+ constructor(env: WabotEnv);
851
+ findBySlug(slug: string): Promise<WhatsApp | null>;
852
+ findByBusinessNumber(number: string): Promise<WhatsApp | null>;
853
+ private getFromEnvVars;
854
+ }
855
+
828
856
  declare function prepareChatContainer(container: DependencyContainer$1, context: IMessageContext, mindsetCtor?: IConstructor<IMindset>): Promise<DependencyContainer$1>;
829
857
 
830
858
  interface IrunChannelProps {
@@ -941,12 +969,4 @@ declare class RamChatRepository implements IChatRepository {
941
969
  private getMemory;
942
970
  }
943
971
 
944
- type IWabotEnvType = 'development' | 'staging' | 'testing' | 'production';
945
- declare class WabotEnv {
946
- private envType;
947
- constructor();
948
- isDevelopment(): boolean;
949
- isProduction(): boolean;
950
- }
951
-
952
- export { AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Container, ControllerMetadataStore, DeepSeekChatBotAdapter, EmailService, ExpressProvider, HttpServerProvider, type IChannelMetadata, type IChatBot, type IChatBotAdapter, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatFunctionCall, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type IConnectionChatMessage, type IConstructor, type ICrudRepository, type IEmailService, type IGetWhatsAppTemplateRequest, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type IOtpService, type IParamConfig, type IParamDecoration, type IPersistentData, type IPgRepositoryConfig, type IReceivedMessage, type IReceivedMessageItem, type IReversibleMapper, type ISendEmailRequest, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type IServerConfig, type IServerProvider, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type ISystemFunctionCallItem, type ISystemMessageItem, type ITelegramChannelConfig, type IUserConnection, type IUserData, type IUserRepository, type IWabotEnvType, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppContact, type IWhatsAppData, type IWhatsAppMessage, type IWhatsAppMessageListener, type IWhatsAppSenderOptions, type IWhatsAppTemplateMessage, type IWhatsAppTemplateParameter, type IWhatsAppWebhookPayload, type IWhatsappChannelConfig, type IchatControllerConfig, type IrunChannelProps, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, MessageContext, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatBotAdapter, OtpService, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgRepositoryBase, PgUserRepository, RamChatMemory, RamChatRepository, RamUserRepository, RegisterUserModule, RegisterUserWithEmailRequest, SendOneTimePasswordRequest, SocketChannel, SocketChannelConfig, SocketServerProvider, TelegramChannel, TelegramChannelConfig, User, UserRepository, UserResolver, ValidateOneTimePasswordRequest, WabotEnv, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, chatBot, chatController, cmd, container, inject, injectable, isOptional, mindset, mindsetFunction, mindsetModule, param, prepareChatContainer, runChannel, runServer, singleton, socket, telegram, whatsapp };
972
+ export { AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Container, ControllerMetadataStore, DeepSeekChatBotAdapter, EmailService, EnvWhatsAppRepository, ExpressProvider, HttpServerProvider, type IChannelMetadata, type IChatBot, type IChatBotAdapter, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatFunctionCall, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type IConnectionChatMessage, type IConstructor, type ICrudRepository, type IEmailService, type IGetWhatsAppTemplateRequest, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type IOtpService, type IParamConfig, type IParamDecoration, type IPersistentData, type IPgRepositoryConfig, type IReceivedMessage, type IReceivedMessageItem, type IReversibleMapper, type ISendEmailRequest, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type IServerConfig, type IServerProvider, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type ISystemFunctionCallItem, type ISystemMessageItem, type ITelegramChannelConfig, type IUserConnection, type IUserData, type IUserRepository, type IWabotEnvType, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppContact, type IWhatsAppData, type IWhatsAppMessage, type IWhatsAppMessageListener, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsAppTemplateMessage, type IWhatsAppTemplateParameter, type IWhatsAppWebhookPayload, type IWhatsappChannelConfig, type IchatControllerConfig, type IrunChannelProps, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, MessageContext, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatBotAdapter, OtpService, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgRepositoryBase, PgUserRepository, PgWhatsAppRepository, RamChatMemory, RamChatRepository, RamUserRepository, RegisterUserModule, RegisterUserWithEmailRequest, SendOneTimePasswordRequest, SocketChannel, SocketChannelConfig, SocketServerProvider, TelegramChannel, TelegramChannelConfig, User, UserRepository, UserResolver, ValidateOneTimePasswordRequest, WabotEnv, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, chatBot, chatController, cmd, container, inject, injectable, isOptional, mindset, mindsetFunction, mindsetModule, param, prepareChatContainer, runChannel, runServer, singleton, socket, telegram, whatsapp };
package/dist/src/index.js CHANGED
@@ -22,6 +22,8 @@ export { WhatsAppRepository } from './channels/whatsapp/WhatsAppRepository.js';
22
22
  export { WhatsAppSender } from './channels/whatsapp/WhatsAppSender.js';
23
23
  export { WhatsAppSenderByDevConnection } from './channels/whatsapp/WhatsAppSenderByDevConnection.js';
24
24
  export { WhatsAppSenderByCloudApi } from './channels/whatsapp/WhatsAppSenderByCloudApi.js';
25
+ export { PgWhatsAppRepository } from './channels/whatsapp/PgWhatsAppRepository.js';
26
+ export { EnvWhatsAppRepository } from './channels/whatsapp/EnvWhatsAppRepository.js';
25
27
  export { chatBot } from './chatbot/metadata/@chatBot.js';
26
28
  export { ChatBotMetadataStore } from './chatbot/metadata/ChatBotMetadataStore.js';
27
29
  export { ChatBot } from './chatbot/ChatBot.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wabot-dev/framework",
3
- "version": "0.1.0-beta.3",
3
+ "version": "0.1.0-beta.4",
4
4
  "description": "Framework for IA Chat Bots",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",