cogfy-messenger 0.1.0 → 0.1.2

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 (84) hide show
  1. package/dist/clients/base-client.d.ts +8 -0
  2. package/dist/clients/base-client.js +9 -0
  3. package/dist/clients/contacts/contacts-client.d.ts +34 -0
  4. package/dist/clients/contacts/contacts-client.js +66 -0
  5. package/dist/clients/contacts/index.d.ts +2 -0
  6. package/dist/clients/contacts/index.js +18 -0
  7. package/dist/clients/contacts/types/create-contact.d.ts +15 -0
  8. package/dist/clients/contacts/types/create-contact.js +2 -0
  9. package/{src/clients/contacts/types/delete-contact.ts → dist/clients/contacts/types/delete-contact.d.ts} +2 -2
  10. package/dist/clients/contacts/types/delete-contact.js +2 -0
  11. package/dist/clients/contacts/types/get-contact.d.ts +18 -0
  12. package/dist/clients/contacts/types/get-contact.js +2 -0
  13. package/dist/clients/contacts/types/index.d.ts +5 -0
  14. package/dist/clients/contacts/types/index.js +21 -0
  15. package/dist/clients/contacts/types/list-contacts.d.ts +20 -0
  16. package/dist/clients/contacts/types/list-contacts.js +2 -0
  17. package/dist/clients/contacts/types/update-contact.d.ts +14 -0
  18. package/dist/clients/contacts/types/update-contact.js +2 -0
  19. package/dist/clients/conversations/conversations-client.d.ts +24 -0
  20. package/dist/clients/conversations/conversations-client.js +57 -0
  21. package/dist/clients/conversations/index.d.ts +2 -0
  22. package/dist/clients/conversations/index.js +18 -0
  23. package/dist/clients/conversations/types/get-conversation.d.ts +11 -0
  24. package/dist/clients/conversations/types/get-conversation.js +2 -0
  25. package/dist/clients/conversations/types/get-messages.d.ts +35 -0
  26. package/dist/clients/conversations/types/get-messages.js +2 -0
  27. package/dist/clients/conversations/types/index.d.ts +4 -0
  28. package/dist/clients/conversations/types/index.js +20 -0
  29. package/dist/clients/conversations/types/list-conversations.d.ts +30 -0
  30. package/dist/clients/conversations/types/list-conversations.js +2 -0
  31. package/dist/clients/conversations/types/send-message.d.ts +12 -0
  32. package/dist/clients/conversations/types/send-message.js +2 -0
  33. package/dist/clients/index.d.ts +2 -0
  34. package/dist/clients/index.js +18 -0
  35. package/dist/clients/tags/index.d.ts +2 -0
  36. package/dist/clients/tags/index.js +18 -0
  37. package/dist/clients/tags/tags-client.d.ts +34 -0
  38. package/dist/clients/tags/tags-client.js +66 -0
  39. package/{src/clients/tags/types/create-tag.ts → dist/clients/tags/types/create-tag.d.ts} +5 -6
  40. package/dist/clients/tags/types/create-tag.js +2 -0
  41. package/dist/clients/tags/types/delete-tag.d.ts +4 -0
  42. package/dist/clients/tags/types/delete-tag.js +2 -0
  43. package/dist/clients/tags/types/get-tag.d.ts +4 -0
  44. package/dist/clients/tags/types/get-tag.js +2 -0
  45. package/dist/clients/tags/types/index.d.ts +5 -0
  46. package/dist/clients/tags/types/index.js +21 -0
  47. package/dist/clients/tags/types/list-tags.d.ts +6 -0
  48. package/dist/clients/tags/types/list-tags.js +2 -0
  49. package/{src/clients/tags/types/update-tag.ts → dist/clients/tags/types/update-tag.d.ts} +5 -6
  50. package/dist/clients/tags/types/update-tag.js +2 -0
  51. package/dist/cogfy-messenger.d.ts +13 -0
  52. package/dist/cogfy-messenger.js +27 -0
  53. package/dist/index.d.ts +2 -0
  54. package/dist/index.js +18 -0
  55. package/package.json +5 -2
  56. package/.github/workflows/tests.yml +0 -18
  57. package/src/clients/base-client.ts +0 -13
  58. package/src/clients/contacts/contacts-client.test.ts +0 -89
  59. package/src/clients/contacts/contacts-client.ts +0 -49
  60. package/src/clients/contacts/index.ts +0 -2
  61. package/src/clients/contacts/types/create-contact.ts +0 -16
  62. package/src/clients/contacts/types/get-contact.ts +0 -18
  63. package/src/clients/contacts/types/index.ts +0 -5
  64. package/src/clients/contacts/types/list-contacts.ts +0 -20
  65. package/src/clients/contacts/types/update-contact.ts +0 -15
  66. package/src/clients/conversations/conversations-client.test.ts +0 -56
  67. package/src/clients/conversations/conversations-client.ts +0 -41
  68. package/src/clients/conversations/index.ts +0 -2
  69. package/src/clients/conversations/types/get-conversation.ts +0 -11
  70. package/src/clients/conversations/types/get-messages.ts +0 -35
  71. package/src/clients/conversations/types/index.ts +0 -4
  72. package/src/clients/conversations/types/list-conversations.ts +0 -37
  73. package/src/clients/conversations/types/send-message.ts +0 -13
  74. package/src/clients/index.ts +0 -2
  75. package/src/clients/tags/index.ts +0 -2
  76. package/src/clients/tags/tags-client.test.ts +0 -80
  77. package/src/clients/tags/tags-client.ts +0 -49
  78. package/src/clients/tags/types/delete-tag.ts +0 -4
  79. package/src/clients/tags/types/get-tag.ts +0 -4
  80. package/src/clients/tags/types/index.ts +0 -5
  81. package/src/clients/tags/types/list-tags.ts +0 -6
  82. package/src/cogfy-messenger.ts +0 -33
  83. package/src/index.ts +0 -2
  84. package/tsconfig.json +0 -16
@@ -0,0 +1,66 @@
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.TagsClient = void 0;
13
+ const base_client_1 = require("../base-client");
14
+ class TagsClient extends base_client_1.BaseClient {
15
+ /**
16
+ * Calls the POST /tags endpoint
17
+ * @param payload The tag data to create
18
+ * @returns An object with the ID and the name of the newly created tag
19
+ */
20
+ create(payload) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ return (yield this.axios.post('/tags', payload)).data;
23
+ });
24
+ }
25
+ /**
26
+ * Calls the DELETE /tags/:id endpoint
27
+ * @param id The ID of the tag to delete
28
+ * @returns An object with the ID and the name of the deleted tag
29
+ */
30
+ delete(id) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ return (yield this.axios.delete(`/tags/${id}`)).data;
33
+ });
34
+ }
35
+ /**
36
+ * Calls the GET /tags/:id endpoint
37
+ * @param id The ID of the tag to retrieve
38
+ * @returns The tag with the specified ID
39
+ */
40
+ get(id) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ return (yield this.axios.get(`/tags/${id}`)).data;
43
+ });
44
+ }
45
+ /**
46
+ * Calls the GET /tags endpoint
47
+ * @returns A list of all tags in the workspace
48
+ */
49
+ list() {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ return (yield this.axios.get('/tags')).data;
52
+ });
53
+ }
54
+ /**
55
+ * Calls the PATCH /tags/:id endpoint
56
+ * @param id The ID of the tag to update
57
+ * @param payload The updated tag data
58
+ * @returns An object with the ID and the name of the updated tag
59
+ */
60
+ update(id, payload) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ return (yield this.axios.patch(`/tags/${id}`, payload)).data;
63
+ });
64
+ }
65
+ }
66
+ exports.TagsClient = TagsClient;
@@ -1,8 +1,7 @@
1
1
  export type CreateTagCommand = {
2
- name: string
3
- }
4
-
2
+ name: string;
3
+ };
5
4
  export type CreateTagResult = {
6
- id: string
7
- name: string
8
- }
5
+ id: string;
6
+ name: string;
7
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export type DeleteTagResult = {
2
+ id: string;
3
+ name: string;
4
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export type GetTagResult = {
2
+ id: string;
3
+ name: string;
4
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export * from './create-tag';
2
+ export * from './delete-tag';
3
+ export * from './get-tag';
4
+ export * from './list-tags';
5
+ export * from './update-tag';
@@ -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("./create-tag"), exports);
18
+ __exportStar(require("./delete-tag"), exports);
19
+ __exportStar(require("./get-tag"), exports);
20
+ __exportStar(require("./list-tags"), exports);
21
+ __exportStar(require("./update-tag"), exports);
@@ -0,0 +1,6 @@
1
+ export type ListTagsResult = {
2
+ data: {
3
+ id: string;
4
+ name: string;
5
+ }[];
6
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,8 +1,7 @@
1
1
  export type UpdateTagCommand = {
2
- name: string
3
- }
4
-
2
+ name: string;
3
+ };
5
4
  export type UpdateTagResult = {
6
- id: string
7
- name: string
8
- }
5
+ id: string;
6
+ name: string;
7
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,13 @@
1
+ import { ContactsClient } from './clients/contacts';
2
+ import { TagsClient } from './clients/tags';
3
+ import { ConversationsClient } from './clients/conversations';
4
+ export type CogfyMessengerOptions = {
5
+ apiKey: string;
6
+ baseURL?: string;
7
+ };
8
+ export declare class CogfyMessenger {
9
+ contacts: ContactsClient;
10
+ conversations: ConversationsClient;
11
+ tags: TagsClient;
12
+ constructor(options: CogfyMessengerOptions);
13
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CogfyMessenger = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const contacts_1 = require("./clients/contacts");
9
+ const tags_1 = require("./clients/tags");
10
+ const conversations_1 = require("./clients/conversations");
11
+ const DEFAULT_BASE_URL = 'https://messenger-public-api.cogfy.com';
12
+ class CogfyMessenger {
13
+ constructor(options) {
14
+ const clientOptions = {
15
+ axios: axios_1.default.create({
16
+ baseURL: options.baseURL || DEFAULT_BASE_URL,
17
+ headers: {
18
+ 'api-key': options.apiKey
19
+ }
20
+ })
21
+ };
22
+ this.contacts = new contacts_1.ContactsClient(clientOptions);
23
+ this.conversations = new conversations_1.ConversationsClient(clientOptions);
24
+ this.tags = new tags_1.TagsClient(clientOptions);
25
+ }
26
+ }
27
+ exports.CogfyMessenger = CogfyMessenger;
@@ -0,0 +1,2 @@
1
+ export * from './clients';
2
+ export * from './cogfy-messenger';
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
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("./clients"), exports);
18
+ __exportStar(require("./cogfy-messenger"), exports);
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "cogfy-messenger",
3
- "version": "0.1.0",
4
- "main": "index.js",
3
+ "version": "0.1.2",
4
+ "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "rimraf dist && tsc",
7
7
  "prepublishOnly": "npm run build",
8
8
  "test": "vitest"
9
9
  },
10
+ "files": [
11
+ "dist"
12
+ ],
10
13
  "keywords": [],
11
14
  "author": "",
12
15
  "license": "ISC",
@@ -1,18 +0,0 @@
1
- on: [push, workflow_dispatch]
2
-
3
- jobs:
4
- tests:
5
- timeout-minutes: 5
6
- runs-on: ubuntu-latest
7
- steps:
8
- - uses: actions/checkout@v4
9
- with:
10
- fetch-depth: 0
11
- - uses: actions/setup-node@v4
12
- with:
13
- node-version: 22.x
14
- cache: npm
15
- cache-dependency-path: package-lock.json
16
- - run: npm ci
17
- - run: npm run test
18
- - run: npm run build
@@ -1,13 +0,0 @@
1
- import { AxiosInstance } from 'axios'
2
-
3
- export type BaseClientOptions = {
4
- axios: AxiosInstance
5
- }
6
-
7
- export abstract class BaseClient {
8
- protected axios: AxiosInstance
9
-
10
- constructor (options: BaseClientOptions) {
11
- this.axios = options.axios
12
- }
13
- }
@@ -1,89 +0,0 @@
1
- import AxiosMockAdapter from 'axios-mock-adapter'
2
- import { afterEach, describe, expect, test } from 'vitest'
3
- import { CogfyMessenger } from '../../cogfy-messenger'
4
- import axios from 'axios'
5
- import { faker } from '@faker-js/faker'
6
-
7
- describe('contacts', () => {
8
- const mock = new AxiosMockAdapter(axios)
9
- const cogfy = new CogfyMessenger({ apiKey: 'test' })
10
-
11
- afterEach(() => {
12
- mock.restore()
13
- })
14
-
15
- describe('list', () => {
16
- test('calls the list endpoint', async () => {
17
- mock.onGet('/contacts').reply(200, { data: [{ id: '1' }]})
18
-
19
- const result = await cogfy.contacts.list()
20
-
21
- expect(result).toMatchObject({ data: [{ id: '1' }] })
22
- })
23
- })
24
-
25
- describe('get', () => {
26
- test('calls the get endpoint', async () => {
27
- const randomId = faker.string.uuid()
28
- mock.onGet(`/contacts/${randomId}`).reply(200, { id: randomId })
29
-
30
- const result = await cogfy.contacts.get(randomId)
31
-
32
- expect(result).toMatchObject({ id: randomId })
33
- })
34
- })
35
-
36
- describe('create', () => {
37
- test('calls the create endpoint', async () => {
38
- const randomId = faker.string.uuid()
39
- mock.onPost(`/contacts`).reply(201, { id: randomId })
40
-
41
- const result = await cogfy.contacts.create({
42
- waProfileName: faker.person.fullName(),
43
- firstName: faker.person.firstName(),
44
- lastName: faker.person.lastName(),
45
- email: faker.internet.email(),
46
- phone: faker.phone.number(),
47
- occupation: faker.person.jobTitle(),
48
- gender: faker.person.gender(),
49
- birthdate: faker.date.birthdate().toISOString(),
50
- age: faker.number.int({ min: 18, max: 80 }),
51
- notes: faker.lorem.sentence()
52
- })
53
-
54
- expect(result).toMatchObject({ id: randomId })
55
- })
56
- })
57
-
58
- describe('delete', () => {
59
- test('calls the delete endpoint', async () => {
60
- const randomId = faker.string.uuid()
61
- mock.onDelete(`/contacts/${randomId}`).reply(200, { id: randomId })
62
-
63
- const result = await cogfy.contacts.delete(randomId)
64
-
65
- expect(result).toMatchObject({ id: randomId })
66
- })
67
- })
68
-
69
- describe('update', () => {
70
- test('calls the update endpoint', async () => {
71
- const randomId = faker.string.uuid()
72
- mock.onPatch(`/contacts/${randomId}`).reply(200, { id: randomId })
73
-
74
- const result = await cogfy.contacts.update(randomId, {
75
- firstName: faker.person.firstName(),
76
- lastName: faker.person.lastName(),
77
- email: faker.internet.email(),
78
- phone: faker.phone.number(),
79
- occupation: faker.person.jobTitle(),
80
- gender: faker.person.gender(),
81
- birthdate: faker.date.birthdate().toISOString(),
82
- age: faker.number.int({ min: 18, max: 80 }),
83
- notes: faker.lorem.sentence()
84
- })
85
-
86
- expect(result).toMatchObject({ id: randomId })
87
- })
88
- })
89
- })
@@ -1,49 +0,0 @@
1
- import { BaseClient } from '../base-client'
2
- import { CreateContactCommand, CreateContactResult, DeleteContactResult, GetContactResult, ListContactsResult, UpdateContactCommand, UpdateContactResult } from './types'
3
-
4
- export class ContactsClient extends BaseClient {
5
- /**
6
- * Calls the POST /contacts endpoint
7
- * @param contact The contact data to create
8
- * @returns An object with the ID of the newly created contact
9
- */
10
- async create (contact: CreateContactCommand): Promise<CreateContactResult> {
11
- return (await this.axios.post('/contacts', contact)).data
12
- }
13
-
14
- /**
15
- * Calls the GET /contacts/:id endpoint
16
- * @param id The ID of the contact to retrieve
17
- * @returns The contact with the specified ID
18
- */
19
- async get (id: string): Promise<GetContactResult> {
20
- return (await this.axios.get(`/contacts/${id}`)).data
21
- }
22
-
23
- /**
24
- * Calls the GET /contacts endpoint
25
- * @returns A list of all contacts in the workspace
26
- */
27
- async list (): Promise<ListContactsResult> {
28
- return (await this.axios.get('/contacts')).data
29
- }
30
-
31
- /**
32
- * Calls the PATCH /contacts/:id endpoint
33
- * @param id The ID of the contact to update
34
- * @param contact The updated contact data
35
- * @returns An object with the ID of the updated contact
36
- */
37
- async update (id: string, contact: UpdateContactCommand): Promise<UpdateContactResult> {
38
- return (await this.axios.patch(`/contacts/${id}`, contact)).data
39
- }
40
-
41
- /**
42
- * Calls the DELETE /contacts/:id endpoint
43
- * @param id The ID of the contact to delete
44
- * @returns An object with the ID of the deleted contact
45
- */
46
- async delete (id: string): Promise<DeleteContactResult> {
47
- return (await this.axios.delete(`/contacts/${id}`)).data
48
- }
49
- }
@@ -1,2 +0,0 @@
1
- export * from './contacts-client'
2
- export * from './types'
@@ -1,16 +0,0 @@
1
- export type CreateContactResult = {
2
- id: string
3
- }
4
-
5
- export type CreateContactCommand = {
6
- waProfileName: string | null
7
- firstName: string | null
8
- lastName: string | null
9
- email: string | null
10
- phone: string | null
11
- occupation: string | null
12
- gender: string | null
13
- birthdate: string | null
14
- age: number | null
15
- notes: string | null
16
- }
@@ -1,18 +0,0 @@
1
- export type GetContactResult = {
2
- id: string
3
- workspaceId: string
4
- statusId: string | null
5
- waId: string | null
6
- waProfileName: string | null
7
- firstName: string | null
8
- lastName: string | null
9
- email: string | null
10
- phone: string | null
11
- occupation: string | null
12
- gender: string | null
13
- birthdate: string | null
14
- age: number | null
15
- notes: string | null
16
- createDate: string
17
- updateDate: string
18
- }
@@ -1,5 +0,0 @@
1
- export * from './create-contact'
2
- export * from './update-contact'
3
- export * from './get-contact'
4
- export * from './list-contacts'
5
- export * from './delete-contact'
@@ -1,20 +0,0 @@
1
- export type ListContactsResult = {
2
- data: {
3
- id: string
4
- workspaceId: string
5
- statusId: string | null
6
- waId: string | null
7
- waProfileName: string | null
8
- firstName: string | null
9
- lastName: string | null
10
- email: string | null
11
- phone: string | null
12
- occupation: string | null
13
- gender: string | null
14
- birthdate: string | null
15
- age: number | null
16
- notes: string | null
17
- createDate: string
18
- updateDate: string
19
- }[]
20
- }
@@ -1,15 +0,0 @@
1
- export type UpdateContactCommand = {
2
- firstName: string | null
3
- lastName: string | null
4
- email: string | null
5
- phone: string | null
6
- occupation: string | null
7
- gender: string | null
8
- birthdate: string | null
9
- age: number | null
10
- notes: string | null
11
- }
12
-
13
- export type UpdateContactResult = {
14
- id: string
15
- }
@@ -1,56 +0,0 @@
1
- import AxiosMockAdapter from 'axios-mock-adapter'
2
- import { ConversationsClient } from './conversations-client'
3
- import axios from 'axios'
4
- import { CogfyMessenger } from '../../cogfy-messenger'
5
- import { faker } from '@faker-js/faker'
6
- import { describe, expect, it, beforeEach } from 'vitest'
7
-
8
- describe(ConversationsClient, () => {
9
- const axiosMock = new AxiosMockAdapter(axios)
10
- const cogfy = new CogfyMessenger({ apiKey: 'test' })
11
-
12
- beforeEach(() => {
13
- axiosMock.restore()
14
- })
15
-
16
- describe(ConversationsClient.prototype.get, () => {
17
- it('should call GET /conversations/:id endpoint', async () => {
18
- const id = faker.string.uuid()
19
- const name = faker.lorem.word()
20
- axiosMock.onGet(`/conversations/${id}`).reply(200, { id, name })
21
-
22
- const result = await cogfy.conversations.get(id)
23
-
24
- expect(result).toEqual({ id, name })
25
- })
26
- })
27
-
28
- describe(ConversationsClient.prototype.list, () => {
29
- it('should call GET /conversations endpoint', async () => {
30
- const conversations = Array.from({ length: 3 }, () => ({
31
- id: faker.string.uuid(),
32
- name: faker.lorem.word()
33
- }))
34
- axiosMock.onGet('/conversations').reply(200, { data: conversations })
35
-
36
- const result = await cogfy.conversations.list({ phoneNumberId: faker.string.uuid() })
37
-
38
- expect(result.data).toEqual(conversations)
39
- })
40
- })
41
-
42
- describe('send message', () => {
43
- it('calls the send message endpoint', async () => {
44
- const conversationId = faker.string.uuid()
45
- const messageId = faker.string.uuid()
46
- axiosMock.onPost(`/conversations/${conversationId}/messages`).reply(201, { id: messageId })
47
-
48
- const result = await cogfy.conversations.sendMessage(conversationId, {
49
- type: 'text',
50
- content: faker.lorem.sentence()
51
- })
52
-
53
- expect(result).toMatchObject({ id: messageId })
54
- })
55
- })
56
- })
@@ -1,41 +0,0 @@
1
- import { BaseClient } from '../base-client'
2
- import { SendMessageCommand } from './types/send-message'
3
- import { GetConversationResult, GetMessagesResult, ListConversationsParams, ListConversationsResult, ListMessagesParams } from './types'
4
-
5
- export class ConversationsClient extends BaseClient {
6
- /**
7
- * Calls the GET /conversations/:id endpoint
8
- * @param id The ID of the conversation to retrieve
9
- * @returns The conversation with the specified ID
10
- */
11
- async get (id: string): Promise<GetConversationResult> {
12
- return (await this.axios.get(`/conversations/${id}`)).data
13
- }
14
-
15
- /**
16
- * Calls the GET /conversations endpoint
17
- * @param params Params for listing conversations, such as pagination cursors
18
- * @returns A list of all conversations in the workspace
19
- */
20
- async list (params: ListConversationsParams): Promise<ListConversationsResult> {
21
- const axiosResponse = await this.axios.get(`/conversations`, {
22
- params,
23
- })
24
- return axiosResponse.data
25
- }
26
-
27
- /**
28
- * Calls the GET /conversations/:id/messages endpoint
29
- * @param params Params for listing messages in a conversation, such as pagination cursors
30
- * @returns A list of all messages in the specified conversation
31
- */
32
- async getMessages (params: ListMessagesParams): Promise<GetMessagesResult> {
33
- const axiosResponse = await this.axios.get(`/conversations/${params.conversationId}/messages`, {
34
- params
35
- })
36
- return axiosResponse.data
37
- }
38
- async sendMessage (id: string, payload: SendMessageCommand): Promise<any> {
39
- return (await this.axios.post(`/conversations/${id}/messages`, payload)).data
40
- }
41
- }
@@ -1,2 +0,0 @@
1
- export * from './conversations-client'
2
- export * from './types'
@@ -1,11 +0,0 @@
1
- export type GetConversationResult = {
2
- id: string
3
- workspaceId: string
4
- phoneNumberId: string | null
5
- recipientId: string | null
6
- assigneeId: string | null
7
- lastMessageId: string | null
8
- data: any | null
9
- createDate: string
10
- serviceWindowExpireDate: string | null
11
- }
@@ -1,35 +0,0 @@
1
- export type GetMessagesResult = {
2
- data: {
3
- id: string
4
- workspaceId: string
5
- conversationId: string | null
6
- assistantId: string | null
7
- userId: string | null
8
- broadcastId: string | null
9
- whatsappMessageId: string | null
10
- from: string | null
11
- to: string | null
12
- role: string
13
- status: string | null
14
- type: string | null
15
- content: string | null
16
- contentData: string | null
17
- toolCallId: string | null
18
- toolCalls: string | null
19
- data: string | null
20
- contextId: string | null
21
- contextFrom: string | null
22
- createDate: Date
23
- sendDate: Date
24
- deliverDate: Date | null
25
- readDate: Date | null
26
- promptTokens: number | null
27
- completionTokens: number | null
28
- order: number
29
- traceId: string | null
30
- }[]
31
- cursors: {
32
- next: string | null
33
- prev: string | null
34
- }
35
- }
@@ -1,4 +0,0 @@
1
- export * from './get-conversation'
2
- export * from './get-messages'
3
- export * from './send-message'
4
- export * from './list-conversations'