diff --git a/index.d.ts b/index.d.ts index 11e434d..f46308e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -244,6 +244,25 @@ declare namespace WAWebJS { /** Save new contact to user's addressbook or edit the existing one */ saveOrEditAddressbookContact(phoneNumber: string, firstName: string, lastName: string, syncToAddressbook?: boolean): Promise + /** + * Add or edit a customer note + * @see https://faq.whatsapp.com/1433099287594476 + */ + addOrEditCustomerNote(userId: string, note: string): Promise + + /** + * Get a customer note + * @see https://faq.whatsapp.com/1433099287594476 + */ + getCustomerNote(userId: string): Promise<{ + chatId: string; + content: string; + createdAt: number; + id: string; + modifiedAt: number; + type: string; + }> + /** Deletes the contact from user's addressbook */ deleteAddressbookContact(honeNumber: string): Promise @@ -1707,6 +1726,17 @@ declare namespace WAWebJS { getPinnedMessages: () => Promise<[Message]|[]> /** Sync history conversation of the Chat */ syncHistory: () => Promise + /** Add or edit a customer note */ + addOrEditCustomerNote: (note: string) => Promise + /** Get a customer note */ + getCustomerNote: () => Promise<{ + chatId: string; + content: string; + createdAt: number; + id: string; + modifiedAt: number; + type: string; + }> } export interface Channel { diff --git a/src/Client.js b/src/Client.js index 5162321..8f02a78 100644 --- a/src/Client.js +++ b/src/Client.js @@ -2356,6 +2356,57 @@ class Client extends EventEmitter { })); }, userIds); } + + /** + * Add or edit a customer note + * @see https://faq.whatsapp.com/1433099287594476 + * @param {string} userId The ID of a customer to add a note to + * @param {string} note The note to add + * @returns {Promise} + */ + async addOrEditCustomerNote(userId, note) { + return await this.pupPage.evaluate(async (userId, note) => { + if (!window.Store.BusinessGatingUtils.smbNotesV1Enabled()) return; + + return window.Store.CustomerNoteUtils.noteAddAction( + 'unstructured', + window.Store.WidToJid.widToUserJid(window.Store.WidFactory.createWid(userId)), + note + ); + }, userId, note); + } + + /** + * Get a customer note + * @see https://faq.whatsapp.com/1433099287594476 + * @param {string} userId The ID of a customer to get a note from + * @returns {Promise<{ + * chatId: string, + * content: string, + * createdAt: number, + * id: string, + * modifiedAt: number, + * type: string + * }>} + */ + async getCustomerNote(userId) { + return await this.pupPage.evaluate(async (userId) => { + if (!window.Store.BusinessGatingUtils.smbNotesV1Enabled()) return null; + + const note = await window.Store.CustomerNoteUtils.retrieveOnlyNoteForChatJid( + window.Store.WidToJid.widToUserJid(window.Store.WidFactory.createWid(userId)) + ); + + let serialized = note?.serialize(); + + if (!serialized) return null; + + serialized.chatId = window.Store.JidToWid.userJidToUserWid(serialized.chatJid)._serialized; + delete serialized.chatJid; + + return serialized; + }, userId); + } } module.exports = Client; diff --git a/src/structures/Chat.js b/src/structures/Chat.js index be322c5..7277e21 100644 --- a/src/structures/Chat.js +++ b/src/structures/Chat.js @@ -294,6 +294,36 @@ class Chat extends Base { async syncHistory() { return this.client.syncHistory(this.id._serialized); } + + /** + * Add or edit a customer note + * @see https://faq.whatsapp.com/1433099287594476 + * @param {string} note The note to add + * @returns {Promise} + */ + async addOrEditCustomerNote(note) { + if (this.isGroup || this.isChannel) return; + + return this.client.addOrEditCustomerNote(this.id._serialized, note); + } + + /** + * Get a customer note + * @see https://faq.whatsapp.com/1433099287594476 + * @returns {Promise<{ + * chatId: string, + * content: string, + * createdAt: number, + * id: string, + * modifiedAt: number, + * type: string + * }>} + */ + async getCustomerNote() { + if (this.isGroup || this.isChannel) return null; + + return this.client.getCustomerNote(this.id._serialized); + } } module.exports = Chat; diff --git a/src/util/Injected/Store.js b/src/util/Injected/Store.js index 07c475d..ceb5941 100644 --- a/src/util/Injected/Store.js +++ b/src/util/Injected/Store.js @@ -103,6 +103,8 @@ exports.ExposeStore = () => { window.Store.UploadUtils = window.require('WAWebUploadManager'); window.Store.WAWebStreamModel = window.require('WAWebStreamModel'); window.Store.FindOrCreateChat = window.require('WAWebFindChatAction'); + window.Store.CustomerNoteUtils = window.require('WAWebNoteAction'); + window.Store.BusinessGatingUtils = window.require('WAWebBizGatingUtils'); window.Store.Settings = { ...window.require('WAWebUserPrefsGeneral'),