feat: get/add/edit customer notes (#3806)

* feat: add required module

* feat: add 'addOrEditCustomerNote' function

* feat: add 'getCustomerNote' function

* fix: check for logic availability

* feat: add 'Chat.addOrEditCustomerNote'

* feat: add Chat.getCustomerNote
This commit is contained in:
alechkos 2025-09-27 17:35:22 +03:00 • committed by GitHub
commit 7304ec2135
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 113 additions and 0 deletions

View file

@ -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<void>}
*/
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;

View file

@ -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<void>}
*/
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;

View file

@ -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'),