From d35f101fac517203d4ff3901be0dc8afbac13c65 Mon Sep 17 00:00:00 2001 From: Anderson de Oliveira Machado Date: Sat, 29 Feb 2020 14:55:27 -0300 Subject: [PATCH] feat: send typing in chat (#87) Co-authored-by: Pedro S. Lopez --- example.js | 3 +++ src/structures/Chat.js | 12 +++++++++++- src/util/Injected.js | 8 +++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/example.js b/example.js index e42d343..6e92427 100644 --- a/example.js +++ b/example.js @@ -168,6 +168,9 @@ client.on('message', async msg => { } else if (msg.body === '!archive') { const chat = await msg.getChat(); chat.archive(); + } else if (msg.body === '!typing') { + const chat = await msg.getChat(); + chat.typing(); } }); diff --git a/src/structures/Chat.js b/src/structures/Chat.js index 00a87f0..2f7ac52 100644 --- a/src/structures/Chat.js +++ b/src/structures/Chat.js @@ -102,7 +102,17 @@ class Chat extends Base { async unarchive() { return this.client.unarchiveChat(this.id._serialized); } + + /** + * Start typing in chat. This will last for 25 seconds. + */ + async sendTyping() { + return this.client.pupPage.evaluate(chatId => { + window.WWebJS.typing(chatId); + return true; + }, this.id._serialized); + } } -module.exports = Chat; \ No newline at end of file +module.exports = Chat; diff --git a/src/util/Injected.js b/src/util/Injected.js index 14def94..b4728ca 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -255,6 +255,12 @@ exports.LoadUtils = () => { } return false; }; + + window.WWebJS.typing = async (chatId) => { + await window.Store.Wap.sendChatstateComposing(chatId); + return true; + }; + }; exports.MarkAllRead = () => { @@ -272,4 +278,4 @@ exports.MarkAllRead = () => { window.Store.Wap.sendConversationSeen(chat.id, chat.getLastMsgKeyForAction(), chat.unreadCount - chat.pendingSeenCount); } } -}; \ No newline at end of file +};