cogfy-messenger 0.1.2 → 0.1.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.
Files changed (25) hide show
  1. package/dist/clients/broadcasts/broadcasts-client.d.ts +28 -0
  2. package/dist/clients/broadcasts/broadcasts-client.js +56 -0
  3. package/dist/clients/broadcasts/index.d.ts +1 -0
  4. package/dist/clients/broadcasts/index.js +17 -0
  5. package/dist/clients/broadcasts/types/broadcast-status.d.ts +1 -0
  6. package/dist/clients/broadcasts/types/broadcast-status.js +2 -0
  7. package/dist/clients/broadcasts/types/create-broadcast.d.ts +16 -0
  8. package/dist/clients/broadcasts/types/create-broadcast.js +2 -0
  9. package/dist/clients/broadcasts/types/get-broadcast.d.ts +6 -0
  10. package/dist/clients/broadcasts/types/get-broadcast.js +2 -0
  11. package/dist/clients/broadcasts/types/index.d.ts +5 -0
  12. package/dist/clients/broadcasts/types/index.js +21 -0
  13. package/dist/clients/broadcasts/types/list-broadcasts.d.ts +8 -0
  14. package/dist/clients/broadcasts/types/list-broadcasts.js +2 -0
  15. package/dist/clients/broadcasts/types/send-broadcast.d.ts +3 -0
  16. package/dist/clients/broadcasts/types/send-broadcast.js +2 -0
  17. package/dist/clients/conversations/conversations-client.d.ts +16 -3
  18. package/dist/clients/conversations/conversations-client.js +17 -0
  19. package/dist/clients/conversations/types/index.d.ts +2 -1
  20. package/dist/clients/conversations/types/index.js +2 -1
  21. package/dist/clients/conversations/types/send-interactive-order-details-message.d.ts +81 -0
  22. package/dist/clients/conversations/types/send-interactive-order-details-message.js +2 -0
  23. package/dist/cogfy-messenger.d.ts +2 -0
  24. package/dist/cogfy-messenger.js +2 -0
  25. package/package.json +1 -1
@@ -0,0 +1,28 @@
1
+ import { BaseClient } from '../base-client';
2
+ import { CreateBroadcastCommand, CreateBroadcastResult, GetBroadcastResult, ListBroadcastsResult, SendBroadcastCommand } from './types';
3
+ export declare class BroadcastsClient extends BaseClient {
4
+ /**
5
+ * Calls the POST /broadcasts endpoint to create a new broadcast
6
+ * @param broadcast The broadcast data to create
7
+ * @returns The created broadcast
8
+ */
9
+ create(broadcast: CreateBroadcastCommand): Promise<CreateBroadcastResult>;
10
+ /**
11
+ * Calls the GET /broadcasts/:id endpoint to retrieve a broadcast by ID
12
+ * @param id The ID of the broadcast to retrieve
13
+ * @returns The requested broadcast
14
+ */
15
+ get(id: string): Promise<GetBroadcastResult>;
16
+ /**
17
+ * Calls the GET /broadcasts endpoint to retrieve all broadcasts
18
+ * @returns A list of all broadcasts
19
+ */
20
+ list(): Promise<ListBroadcastsResult>;
21
+ /**
22
+ * Calls the POST /broadcasts/:id/send endpoint to send a broadcast
23
+ * @param id The ID of the broadcast to send
24
+ * @param command The send broadcast command
25
+ * @returns A promise that resolves when the broadcast is sent
26
+ */
27
+ send(id: string, command: SendBroadcastCommand): Promise<void>;
28
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.BroadcastsClient = void 0;
13
+ const base_client_1 = require("../base-client");
14
+ class BroadcastsClient extends base_client_1.BaseClient {
15
+ /**
16
+ * Calls the POST /broadcasts endpoint to create a new broadcast
17
+ * @param broadcast The broadcast data to create
18
+ * @returns The created broadcast
19
+ */
20
+ create(broadcast) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ return (yield this.axios.post('/broadcasts', broadcast)).data;
23
+ });
24
+ }
25
+ /**
26
+ * Calls the GET /broadcasts/:id endpoint to retrieve a broadcast by ID
27
+ * @param id The ID of the broadcast to retrieve
28
+ * @returns The requested broadcast
29
+ */
30
+ get(id) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ return (yield this.axios.get(`/broadcasts/${id}`)).data;
33
+ });
34
+ }
35
+ /**
36
+ * Calls the GET /broadcasts endpoint to retrieve all broadcasts
37
+ * @returns A list of all broadcasts
38
+ */
39
+ list() {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ return (yield this.axios.get('/broadcasts')).data;
42
+ });
43
+ }
44
+ /**
45
+ * Calls the POST /broadcasts/:id/send endpoint to send a broadcast
46
+ * @param id The ID of the broadcast to send
47
+ * @param command The send broadcast command
48
+ * @returns A promise that resolves when the broadcast is sent
49
+ */
50
+ send(id, command) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ yield this.axios.post(`/broadcasts/${id}/send`, command);
53
+ });
54
+ }
55
+ }
56
+ exports.BroadcastsClient = BroadcastsClient;
@@ -0,0 +1 @@
1
+ export * from './broadcasts-client';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./broadcasts-client"), exports);
@@ -0,0 +1 @@
1
+ export type BroadcastStatus = 'draft' | 'failed' | 'pending' | 'sent';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,16 @@
1
+ export type CreateBroadcastCommand = {
2
+ type: 'text';
3
+ title: string;
4
+ content: string;
5
+ phoneNumberId: string;
6
+ contactsQuery?: {
7
+ tags?: ({
8
+ id: string;
9
+ } | {
10
+ name: string;
11
+ })[];
12
+ };
13
+ };
14
+ export type CreateBroadcastResult = {
15
+ id: string;
16
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import { BroadcastStatus } from './broadcast-status';
2
+ export type GetBroadcastResult = {
3
+ id: string;
4
+ status: BroadcastStatus;
5
+ createDate: string;
6
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export * from './broadcast-status';
2
+ export * from './create-broadcast';
3
+ export * from './get-broadcast';
4
+ export * from './list-broadcasts';
5
+ export * from './send-broadcast';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./broadcast-status"), exports);
18
+ __exportStar(require("./create-broadcast"), exports);
19
+ __exportStar(require("./get-broadcast"), exports);
20
+ __exportStar(require("./list-broadcasts"), exports);
21
+ __exportStar(require("./send-broadcast"), exports);
@@ -0,0 +1,8 @@
1
+ import { BroadcastStatus } from './broadcast-status';
2
+ export type ListBroadcastsResult = {
3
+ data: {
4
+ id: string;
5
+ status: BroadcastStatus;
6
+ createDate: string;
7
+ }[];
8
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export type SendBroadcastCommand = {
2
+ broadcastId: string;
3
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,6 @@
1
1
  import { BaseClient } from '../base-client';
2
- import { SendMessageCommand } from './types/send-message';
3
- import { GetConversationResult, GetMessagesResult, ListConversationsParams, ListConversationsResult, ListMessagesParams } from './types';
2
+ import { SendMessageCommand, SendMessageResult } from './types/send-message';
3
+ import { GetConversationResult, GetMessagesResult, ListConversationsParams, ListConversationsResult, ListMessagesParams, SendInteractiveOrderDetailsMessageCommand, SendInteractiveOrderDetailsMessageResult } from './types';
4
4
  export declare class ConversationsClient extends BaseClient {
5
5
  /**
6
6
  * Calls the GET /conversations/:id endpoint
@@ -20,5 +20,18 @@ export declare class ConversationsClient extends BaseClient {
20
20
  * @returns A list of all messages in the specified conversation
21
21
  */
22
22
  getMessages(params: ListMessagesParams): Promise<GetMessagesResult>;
23
- sendMessage(id: string, payload: SendMessageCommand): Promise<any>;
23
+ /**
24
+ * Calls the POST /conversations/:id/messages/interactive/order-details endpoint
25
+ * @param id The ID of the conversation to send a message to
26
+ * @param payload The message payload to send
27
+ * @returns The response from the API
28
+ */
29
+ sendInteractiveOrderDetailsMessage(id: string, payload: SendInteractiveOrderDetailsMessageCommand): Promise<SendInteractiveOrderDetailsMessageResult>;
30
+ /**
31
+ * Calls the POST /conversations/:id/messages endpoint
32
+ * @param id The ID of the conversation to send a message to
33
+ * @param payload The message payload to send
34
+ * @returns The response from the API
35
+ */
36
+ sendMessage(id: string, payload: SendMessageCommand): Promise<SendMessageResult>;
24
37
  }
@@ -48,6 +48,23 @@ class ConversationsClient extends base_client_1.BaseClient {
48
48
  return axiosResponse.data;
49
49
  });
50
50
  }
51
+ /**
52
+ * Calls the POST /conversations/:id/messages/interactive/order-details endpoint
53
+ * @param id The ID of the conversation to send a message to
54
+ * @param payload The message payload to send
55
+ * @returns The response from the API
56
+ */
57
+ sendInteractiveOrderDetailsMessage(id, payload) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ return (yield this.axios.post(`/conversations/${id}/messages/interactive/order-details`, payload)).data;
60
+ });
61
+ }
62
+ /**
63
+ * Calls the POST /conversations/:id/messages endpoint
64
+ * @param id The ID of the conversation to send a message to
65
+ * @param payload The message payload to send
66
+ * @returns The response from the API
67
+ */
51
68
  sendMessage(id, payload) {
52
69
  return __awaiter(this, void 0, void 0, function* () {
53
70
  return (yield this.axios.post(`/conversations/${id}/messages`, payload)).data;
@@ -1,4 +1,5 @@
1
1
  export * from './get-conversation';
2
2
  export * from './get-messages';
3
- export * from './send-message';
4
3
  export * from './list-conversations';
4
+ export * from './send-interactive-order-details-message';
5
+ export * from './send-message';
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./get-conversation"), exports);
18
18
  __exportStar(require("./get-messages"), exports);
19
- __exportStar(require("./send-message"), exports);
20
19
  __exportStar(require("./list-conversations"), exports);
20
+ __exportStar(require("./send-interactive-order-details-message"), exports);
21
+ __exportStar(require("./send-message"), exports);
@@ -0,0 +1,81 @@
1
+ export type SendInteractiveOrderDetailsMessageCommand = {
2
+ content: InteractiveOrderDetailsContent;
3
+ };
4
+ export type SendInteractiveOrderDetailsMessageResult = {
5
+ id: string;
6
+ };
7
+ type Amount = {
8
+ value: number;
9
+ offset: number;
10
+ description?: string;
11
+ };
12
+ type PaymentSettingsTypePixDynamicCode = {
13
+ type: 'pix_dynamic_code';
14
+ pix_dynamic_code: {
15
+ code: string;
16
+ merchant_name: string;
17
+ key: string;
18
+ key_type: string;
19
+ };
20
+ };
21
+ type PaymentSettingsTypePaymentLink = {
22
+ type: 'payment_link';
23
+ payment_link: {
24
+ uri: string;
25
+ };
26
+ };
27
+ type PaymentSettingsTypeBoleto = {
28
+ type: 'boleto';
29
+ boleto: {
30
+ digitable_line: string;
31
+ };
32
+ };
33
+ type InteractiveOrderDetailsContent = {
34
+ type: 'order_details';
35
+ body: {
36
+ text: string;
37
+ };
38
+ action: {
39
+ name: string;
40
+ parameters: {
41
+ reference_id: string;
42
+ type: string;
43
+ payment_type: string;
44
+ payment_settings?: Array<PaymentSettingsTypePixDynamicCode | PaymentSettingsTypePaymentLink | PaymentSettingsTypeBoleto>;
45
+ currency: string;
46
+ total_amount: Amount;
47
+ order: {
48
+ status: string;
49
+ catalog_id?: string;
50
+ shipping?: Amount;
51
+ expiration?: {
52
+ description: string;
53
+ timestamp: string;
54
+ };
55
+ tax: Amount;
56
+ discount?: Amount & {
57
+ discount_program_name?: string;
58
+ };
59
+ items: {
60
+ retailer_id: string;
61
+ name: string;
62
+ amount: Amount;
63
+ quantity: number;
64
+ sale_amount?: Amount;
65
+ }[];
66
+ subtotal: Amount;
67
+ };
68
+ };
69
+ };
70
+ header?: {
71
+ type: 'image';
72
+ image: {
73
+ link: string;
74
+ provider?: string;
75
+ };
76
+ };
77
+ footer?: {
78
+ text: string;
79
+ };
80
+ };
81
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +1,13 @@
1
1
  import { ContactsClient } from './clients/contacts';
2
2
  import { TagsClient } from './clients/tags';
3
3
  import { ConversationsClient } from './clients/conversations';
4
+ import { BroadcastsClient } from './clients/broadcasts';
4
5
  export type CogfyMessengerOptions = {
5
6
  apiKey: string;
6
7
  baseURL?: string;
7
8
  };
8
9
  export declare class CogfyMessenger {
10
+ broadcasts: BroadcastsClient;
9
11
  contacts: ContactsClient;
10
12
  conversations: ConversationsClient;
11
13
  tags: TagsClient;
@@ -8,6 +8,7 @@ const axios_1 = __importDefault(require("axios"));
8
8
  const contacts_1 = require("./clients/contacts");
9
9
  const tags_1 = require("./clients/tags");
10
10
  const conversations_1 = require("./clients/conversations");
11
+ const broadcasts_1 = require("./clients/broadcasts");
11
12
  const DEFAULT_BASE_URL = 'https://messenger-public-api.cogfy.com';
12
13
  class CogfyMessenger {
13
14
  constructor(options) {
@@ -19,6 +20,7 @@ class CogfyMessenger {
19
20
  }
20
21
  })
21
22
  };
23
+ this.broadcasts = new broadcasts_1.BroadcastsClient(clientOptions);
22
24
  this.contacts = new contacts_1.ContactsClient(clientOptions);
23
25
  this.conversations = new conversations_1.ConversationsClient(clientOptions);
24
26
  this.tags = new tags_1.TagsClient(clientOptions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogfy-messenger",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "rimraf dist && tsc",