A simple WhatsApp Web API (WAPI) that allow you to collect Chat, Contact, and Send Message(s)
Install
NPM
npm i --save @wayfu/simple-wapi
In your app.js import and initialized the module like normal.
import WAPI from "@wayfu/simple-wapi";
Vanilla
If you wish to skip the modular build and NOT use npm you can use the vanilla build like so:
CDN
<script src="https://unpkg.com/@wayfu/simple-wapi@latest/dist/index.min.js"></script>
How to use it:
let WwJS = WAPI.init(window);
window.WwJS = WAPI.init(window);
You need 1 parameter for initiating WAPI. The parameter should be a window
instance of the page. You can use this script to inject the WhatsApp Web on the browser too.
API
#WAPI
Available properties in WAPI
class
WA_VERSION: string;
WAPI_VERSION: string;
WebClasses:{
[k:string]:{ [k:string]: string }
};
ME: WAPI.Contact;
Available function in WAPI
class
let WwJS = WAPI.init(window);
let checked = await WwJS.checkPhone('85726xxx');
let chat = await WwJS.findChat('85726xxx');
let chat = await WwJS.Chat.find('85726xxx');
let contact = await WwJS.findContact('85726xxx');
let contact = await WwJS.Contact.find('85726xxx');
let group = await WwJS.findGroup('120363xxx');
let group = await WwJS.GroupMetadata.find('120363xxx');
let activeChat = WwJS.getActiveChat();
let allGroups = WwJS.getAllGroups();
await WwJS.openChat('85726xxx');
await WwJS.closeChat('85726xxx');
await WwJS.inputAndSendTextMsg('85726xxx', 'text message');
await WwJS.sendMessage('85726xxx', 'test message');
await WwJS.sendMessage('85726xxx', 'caption', {media: file})
await WwJS.sendMessage('85726xxx', '', {media: file, caption: 'caption'})
await WwJS.sleep(2000);
#Chat
Available properties in our Chat
class
id: ChatId,
isGroup: boolean,
active: boolean,
hasDraftMessage: boolean,
name: string,
timestamp: number,
contact: Contact,
Available function in our Chat
class
let WwJS = WAPI.init(window);
let chat = await WwJS.findChat('85726xxx');
let chat = await WwJS.Chat.find('85726xxx')?.getModel();
chat.clearDraft();
await chat.open();
await chat.close();
await chat.sendText('test message');
await chat.sendMedia(imgFile, 'caption');
GroupChat
Group chat is child of Chat
class with extra properties and function. Available properties in our GroupChat
class
groupMetadata: GroupMetadata;
get owner(): Contact | null;
get participants(): GroupParticipant[];
#Contact
Available properties in our Contact
class
number: string,
isBusiness: boolean,
id: ContactId,
isEnterprise: boolean,
isGroup: boolean,
isUser: boolean,
isBlocked: boolean,
name: string | undefined,
pushname: string,
shortName: string | undefined,
isMe: boolean,
isMyContact: boolean
isWAContact: boolean,
Available function in our Contact
class
let WwJS = WAPI.init(window);
let contact = await WwJS.findContact('85726xxx');
let contact = await WwJS.Contact.find('85726xxx')?.getModel();
let chat = await contact.getChat();
let commonGroup = await contact.getCommonGroups();
#Group
Available properties in our Group
class
announce: boolean;
creation: number;
desc: string;
descId: string;
descOwner: ContactId;
descTime: number;
displayedDesc: string;
groupType: string;
id: GroupId;
name: string;
owner: ContactId;
parentGroupId: GroupId;
size: number;
subGroupsId: GroupId[];
get participants(): GroupParticipant[];
get parentGroup(): Group | null;
get childGroups(): Group[];
Available function in our Group
class
let WwJS = WAPI.init(window);
let group = await WwJS.findGroup('120363xxx');
let group = await WwJS.GroupMetadata.find('120363xxx')?.getModel();
let chat = await group.getChat();
let contact = await group.getContact();
let chat = await group.openChat();
TypeScript
This library comes with TypeScript "typings". If you happen to find any bugs in those, create an issue.
License
Copyright © 2023 Wayfu under ISC License