feat: save contact to addressbook (#3533)
* feat: add respectfull modules * feat: add saveOrEditAddressbookContact function * feat: add deleteAddressbookContact function * refactor: import necessary type for return value * style: fix typo * docs: add ocs * style: fix typo
This commit is contained in:
parent
494a18ddb2
commit
d29eaf7def
3 changed files with 43 additions and 0 deletions
6
index.d.ts
vendored
6
index.d.ts
vendored
|
|
@ -197,6 +197,12 @@ declare namespace WAWebJS {
|
|||
|
||||
/** Sync history conversation of the Chat */
|
||||
syncHistory(chatId: string): Promise<boolean>
|
||||
|
||||
/** Save new contact to user's addressbook or edit the existing one */
|
||||
saveOrEditAddressbookContact(phoneNumber: string, firstName: string, lastName: string, syncToAddressbook?: boolean): Promise<ChatId>
|
||||
|
||||
/** Deletes the contact from user's addressbook */
|
||||
deleteAddressbookContact(honeNumber: string): Promise<void>
|
||||
|
||||
/** Changes and returns the archive state of the Chat */
|
||||
unarchiveChat(chatId: string): Promise<boolean>
|
||||
|
|
|
|||
|
|
@ -1773,6 +1773,39 @@ class Client extends EventEmitter {
|
|||
return false;
|
||||
}, chatId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save new contact to user's addressbook or edit the existing one
|
||||
* @param {string} phoneNumber The contact's phone number in a format "17182222222", where "1" is a country code
|
||||
* @param {string} firstName
|
||||
* @param {string} lastName
|
||||
* @param {boolean} [syncToAddressbook = false] If set to true, the contact will also be saved to the user's address book on their phone. False by default
|
||||
* @returns {Promise<import('..').ChatId>} Object in a wid format
|
||||
*/
|
||||
async saveOrEditAddressbookContact(phoneNumber, firstName, lastName, syncToAddressbook = false)
|
||||
{
|
||||
return await this.pupPage.evaluate(async (phoneNumber, firstName, lastName, syncToAddressbook) => {
|
||||
return await window.Store.AddressbookContactUtils.saveContactAction(
|
||||
phoneNumber,
|
||||
null,
|
||||
firstName,
|
||||
lastName,
|
||||
syncToAddressbook
|
||||
);
|
||||
}, phoneNumber, firstName, lastName, syncToAddressbook);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the contact from user's addressbook
|
||||
* @param {string} phoneNumber The contact's phone number in a format "17182222222", where "1" is a country code
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async deleteAddressbookContact(phoneNumber)
|
||||
{
|
||||
return await this.pupPage.evaluate(async (phoneNumber) => {
|
||||
return await window.Store.AddressbookContactUtils.deleteContactAction(phoneNumber);
|
||||
}, phoneNumber);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Client;
|
||||
|
|
|
|||
|
|
@ -141,6 +141,10 @@ exports.ExposeStore = () => {
|
|||
...window.require('WAWebApiMembershipApprovalRequestStore'),
|
||||
...window.require('WASmaxGroupsMembershipRequestsActionRPC')
|
||||
};
|
||||
window.Store.AddressbookContactUtils = {
|
||||
...window.require('WAWebSaveContactAction'),
|
||||
...window.require('WAWebDeleteContactAction')
|
||||
};
|
||||
|
||||
if (!window.Store.Chat._find || !window.Store.Chat.findImpl) {
|
||||
window.Store.Chat._find = e => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue