Skip to content

Commit

Permalink
feat: Added setOnlinePresence function to define your presence
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Aug 4, 2021
1 parent a122b15 commit 627d1a5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/api/layers/sender.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,14 +760,18 @@ export class SenderLayer extends ListenerLayer {
}

/**
* Stops typing
* Update your online presence
* @category Chat
* @param to Chat id
* @param online true for available presence and false for unavailable
*/
public async stopTyping(to: string) {
return evaluateAndReturn(this.page, ({ to }) => WAPI.stopTyping(to), {
to,
});
public async setOnlinePresence(online: boolean = true) {
return evaluateAndReturn(
this.page,
({ online }) => WAPI.setOnlinePresence(online),
{
online,
}
);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/lib/wapi/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,6 @@ export * from './reject-call';
export * from './set-group-description';
export * from './set-group-property';
export * from './set-group-subject';
export * from './set-online-presence';
export * from './set-temporary-messages';
export * from './star-messages';
28 changes: 28 additions & 0 deletions src/lib/wapi/functions/set-online-presence.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* This file is part of WPPConnect.
*
* WPPConnect is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WPPConnect is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with WPPConnect. If not, see <https://www.gnu.org/licenses/>.
*/

export async function setOnlinePresence(online) {
if (typeof online === 'undefined') {
online = true;
}

if (online) {
await Store.ChatPresence.sendPresenceAvailable();
} else {
await Store.ChatPresence.sendPresenceUnavailable();
}
}
2 changes: 2 additions & 0 deletions src/lib/wapi/wapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ import {
unsubscribePresence,
getMessages,
rejectCall,
setOnlinePresence,
} from './functions';
import {
base64ToFile,
Expand Down Expand Up @@ -284,6 +285,7 @@ if (typeof window.WAPI === 'undefined') {
window.WAPI.sendImageAsStickerGif = sendImageAsSticker;
window.WAPI.startTyping = startTyping;
window.WAPI.stopTyping = stopTyping;
window.WAPI.setOnlinePresence = setOnlinePresence;
window.WAPI.sendLocation = sendLocation;
window.WAPI.openChat = openChat;
window.WAPI.openChatAt = openChatAt;
Expand Down
1 change: 1 addition & 0 deletions src/types/WAPI.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ interface WAPI {
setMessagesAdminsOnly: (chatId: string, option: boolean) => boolean;
setMyName: (name: string) => void;
setMyStatus: (to: string) => void;
setOnlinePresence: (online: boolean) => void;
setProfilePic: (path: string, to?: string) => Promise<boolean>;
setTemporaryMessages: (chatId: string, value: string) => Promise<boolean>;
setTheme: (theme?: string) => boolean;
Expand Down

0 comments on commit 627d1a5

Please sign in to comment.