From a7d47e8d48b7d5df54fac8f7fec2507d7f438463 Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 17 Nov 2025 10:12:13 +0300 Subject: [PATCH 1/2] SDK-40 --- README.md | 25 +++++----- docs/README.md | 25 +++++----- .../async/createGroupAndSendMessageAsync.py | 2 +- examples/async/groupsMethodsAsync.py | 4 +- examples/async/payload.py | 8 ++-- examples/async/sendTypingAsync.py | 14 ++++++ .../async/sending/sendFileByUploadAsync.py | 6 ++- examples/async/sending/sendFileByUrlAsync.py | 2 +- .../sending/sendInteractiveButtonsAsync.py | 4 +- .../sendInteractiveButtonsReplyAsync.py | 2 +- examples/async/sending/sendLocationAsync.py | 2 +- examples/async/sending/sendMessageAsync.py | 2 +- examples/async/sending/sendPollAsync.py | 2 +- .../uploadFileAndSendFileByUrlAsync.py | 2 +- examples/async/serviceMethodsAsync.py | 8 ++-- examples/sync/createGroupAndSendMessage.py | 2 +- examples/sync/sendTyping.py | 15 ++++++ .../sync/sending/sendInteractiveButtons.py | 4 +- .../sending/sendInteractiveButtonsReply.py | 2 +- examples/sync/sending/sendPictureByLink.py | 2 +- examples/sync/sending/sendPictureByUpload.py | 6 ++- examples/sync/sending/sendPoll.py | 2 +- examples/sync/sending/sendTextMessage.py | 2 +- .../sending/uploadFileAndSendFileByUrl.py | 2 +- examples/sync/serviceMethods.py | 6 +-- whatsapp_api_client_python/tools/sending.py | 47 ++++++++++++++----- .../tools/serviceMethods.py | 39 +++++++++++++++ 27 files changed, 168 insertions(+), 69 deletions(-) create mode 100644 examples/async/sendTypingAsync.py create mode 100644 examples/sync/sendTyping.py diff --git a/README.md b/README.md index e91c5b6..9361dd1 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ greenAPI = API.GreenAPI( Link to example: [sendTextMessage.py](./examples/sync/sending/sendTextMessage.py). ``` -response = greenAPI.sending.sendMessage("11001234567@c.us", "Message text") +response = greenAPI.sending.sendMessage("79876543210@c.us", "Message text") print(response.data) ``` @@ -74,7 +74,7 @@ Link to example: [sendMessageAsync.py](./examples/async/sending/sendMessageAsync import asyncio async def main(): - response = await greenAPI.sending.sendMessageAsync("11001234567@c.us", "Message text") + response = await greenAPI.sending.sendMessageAsync("79876543210@c.us", "Message text") print(response.data) asyncio.run(main()) @@ -86,7 +86,7 @@ Link to example: [sendPictureByLink.py](./examples/sync/sending/sendPictureByLin ``` response = greenAPI.sending.sendFileByUrl( - "11001234567@c.us", + "79876543210@c.us", "https://download.samplelib.com/png/sample-clouds2-400x300.png", "sample-clouds2-400x300.png", "Sample PNG" @@ -101,7 +101,7 @@ Link to example: [sendPictureByUpload.py](./examples/sync/sending/sendPictureByU ``` response = greenAPI.sending.sendFileByUpload( - "11001234567@c.us", + "79876543210@c.us", "data/logo.jpg", "logo.jpg", "Available rates" @@ -119,7 +119,7 @@ import asyncio async def main(): response = await greenAPI.sending.sendFileByUploadAsync( - "11001234567@c.us", + "79876543210@c.us", "data/logo.jpg", "logo.jpg", "Available rates" @@ -138,7 +138,7 @@ Link to example: [createGroupAndSendMessage.py](./examples/sync/createGroupAndSe ``` create_group_response = greenAPI.groups.createGroup( - "Group Name", ["11001234567@c.us"] + "Group Name", ["79876543210@c.us"] ) if create_group_response.code == 200: send_message_response = greenAPI.sending.sendMessage( @@ -189,7 +189,7 @@ Link to example: [sendPoll.py](./examples/sync/sending/sendPoll.py). ``` response = greenAPI.sending.sendPoll( - "11001234567@c.us", + "79876543210@c.us", "Please choose a color:", [ {"optionName": "Red"}, @@ -221,13 +221,13 @@ Link to example: [sendInteractiveButtons.py](../examples/sync/sending/sendIntera ``` response = greenAPI.sending.sendInteractiveButtons( - "79001234567@c.us", + "79876543210@c.us", "This is message with buttons!", [{ "type": "call", "buttonId": "1", "buttonText": "Call me", - "phoneNumber": "79001234567" + "phoneNumber": "79876543210" }, { "type": "url", @@ -251,13 +251,13 @@ import asyncio async def main(): response = await greenAPI.sending.sendInteractiveButtonsAsync( - "79001234567@c.us", + "79876543210@c.us", "This is message with buttons!", [{ "type": "call", "buttonId": "1", "buttonText": "Call me", - "phoneNumber": "79001234567" + "phoneNumber": "79876543210" }, { "type": "url", @@ -296,6 +296,8 @@ asyncio.run(main()) | Example of sending interactive buttons asynchronously | [SendInteractiveButtonsAsync.py](../examples/async/sending/sendInteractiveButtonsAsync.py) | | Example of sending interactive buttons with a reply | [SendInteractiveButtonsReply.py](../examples/sync/sending/sendInteractiveButtonsReply.py) | | Example of sending interactive buttons asynchronously with a reply | [SendInteractiveButtonsReplyAsync.py](../examples/async/sending/sendInteractiveButtonsReplyAsync.py) | +| Example of sending a notification about typing or recording audio | [SendTyping.py](../examples/sync/sendTyping.py) | +| Example of sending a notification about typing or recording audio asynchronously | [SendTypingAsync.py](../examples/async/sendTypingAsync.py) | ## The full list of the library methods @@ -357,6 +359,7 @@ asyncio.run(main()) | `serviceMethods.archiveChat` | The method archives the chat | [ArchiveChat](https://green-api.com/en/docs/api/service/archiveChat/) | | `serviceMethods.unarchiveChat` | The method unarchives the chat | [UnarchiveChat](https://green-api.com/en/docs/api/service/unarchiveChat/) | | `serviceMethods.setDisappearingChat` | The method is designed to change the settings of disappearing messages in chats | [SetDisappearingChat](https://green-api.com/en/docs/api/service/SetDisappearingChat/) | +| `serviceMethods.sendTyping` | The method is intended to send a notification about typing or recording audio in the chat | [SendTyping](https://green-api.com/docs/api/service/SendTyping/) | | `webhooks.startReceivingNotifications` | The method is designed to start receiving new notifications | | | `webhooks.stopReceivingNotifications` | The method is designed to stop receiving new notifications | | | `partner.GetInstances` | The method is for getting all the account instances created by the partner. | [GetInstances](https://green-api.com/en/docs/partners/getInstances/) | diff --git a/docs/README.md b/docs/README.md index b2e35b7..6e9d7b7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -60,7 +60,7 @@ greenAPI = API.GreenAPI( Ссылка на пример: [sendTextMessage.py](../examples/sync/sending/sendTextMessage.py). ``` -response = greenAPI.sending.sendMessage("11001234567@c.us", "Message text") +response = greenAPI.sending.sendMessage("79876543210@c.us", "Message text") print(response.data) ``` @@ -74,7 +74,7 @@ print(response.data) import asyncio async def main(): - response = await greenAPI.sending.sendMessageAsync("11001234567@c.us", "Message text") + response = await greenAPI.sending.sendMessageAsync("79876543210@c.us", "Message text") print(response.data) asyncio.run(main()) @@ -86,7 +86,7 @@ asyncio.run(main()) ``` response = greenAPI.sending.sendFileByUrl( - "11001234567@c.us", + "79876543210@c.us", "https://download.samplelib.com/png/sample-clouds2-400x300.png", "sample-clouds2-400x300.png", "Sample PNG" @@ -101,7 +101,7 @@ print(response.data) ``` response = greenAPI.sending.sendFileByUpload( - "11001234567@c.us", + "79876543210@c.us", "data/logo.jpg", "logo.jpg", "Available rates" @@ -120,7 +120,7 @@ import asyncio async def main(): response = await greenAPI.sending.sendFileByUploadAsync( - "11001234567@c.us", + "79876543210@c.us", "data/logo.jpg", "logo.jpg", "Available rates" @@ -139,7 +139,7 @@ asyncio.run(main()) ``` create_group_response = greenAPI.groups.createGroup( - "Group Name", ["11001234567@c.us"] + "Group Name", ["79876543210@c.us"] ) if create_group_response.code == 200: send_message_response = greenAPI.sending.sendMessage( @@ -190,7 +190,7 @@ asyncio.run(main()) ``` response = greenAPI.sending.sendPoll( - "11001234567@c.us", + "79876543210@c.us", "Please choose a color:", [ {"optionName": "Red"}, @@ -222,13 +222,13 @@ print(response.data) ``` response = greenAPI.sending.sendInteractiveButtons( - "79001234567@c.us", + "79876543210@c.us", "This is message with buttons!", [{ "type": "call", "buttonId": "1", "buttonText": "Call me", - "phoneNumber": "79001234567" + "phoneNumber": "79876543210" }, { "type": "url", @@ -252,13 +252,13 @@ import asyncio async def main(): response = await greenAPI.sending.sendInteractiveButtonsAsync( - "79001234567@c.us", + "79876543210@c.us", "This is message with buttons!", [{ "type": "call", "buttonId": "1", "buttonText": "Call me", - "phoneNumber": "79001234567" + "phoneNumber": "79876543210" }, { "type": "url", @@ -297,6 +297,8 @@ asyncio.run(main()) | Пример асинхронной отправки интерактивных кнопок | [SendInteractiveButtonsAsync.py](../examples/async/sending/sendInteractiveButtonsAsync.py) | | Пример отправки интерактивных кнопок с ответом | [SendInteractiveButtonsReply.py](../examples/sync/sending/sendInteractiveButtonsReply.py) | | Пример асинхронной отправки интерактивных кнопок с ответом | [SendInteractiveButtonsReplyAsync.py](../examples/async/sending/sendInteractiveButtonsReplyAsync.py) | +| Пример отправки уведомления о наборе текста или записи аудио | [SendTyping.py](../examples/sync/sendTyping.py) | +| Пример асинхронной отправки уведомления о наборе текста или записи аудио | [SendTypingAsync.py](../examples/async/sendTypingAsync.py) | ## Полный список методов библиотеки @@ -351,6 +353,7 @@ asyncio.run(main()) | `serviceMethods.archiveChat` | Метод архивирует чат | [ArchiveChat](https://green-api.com/docs/api/service/archiveChat/) | | `serviceMethods.unarchiveChat` | Метод разархивирует чат | [UnarchiveChat](https://green-api.com/docs/api/service/unarchiveChat/) | | `serviceMethods.setDisappearingChat` | Метод предназначен для изменения настроек исчезающих сообщений в чатах | [SetDisappearingChat](https://green-api.com/docs/api/service/SetDisappearingChat/) | +| `serviceMethods.sendTyping` | Метод предназначен для отправки уведомления о наборе текста или записи аудио в чат | [SendTyping](https://green-api.com/docs/api/service/SendTyping/) | | `webhooks.startReceivingNotifications` | Метод предназначен для старта получения новых уведомлений | | | `webhooks.stopReceivingNotifications` | Метод предназначен для остановки получения новых уведомлений | | | `partner.GetInstances` | Метод предназначен для получения всех инстансов аккаунтов созданных партнёром. | [GetInstances](https://green-api.com/docs/partners/getInstances/) | diff --git a/examples/async/createGroupAndSendMessageAsync.py b/examples/async/createGroupAndSendMessageAsync.py index b80548f..665a06d 100644 --- a/examples/async/createGroupAndSendMessageAsync.py +++ b/examples/async/createGroupAndSendMessageAsync.py @@ -7,7 +7,7 @@ async def main(): create_group_response = await greenAPI.groups.createGroupAsync( - "SDK Python", ["11001234567@c.us", "11001234568@c.us"] + "SDK Python", ["79876543210@c.us", "11001234568@c.us"] ) if create_group_response.code == 200: diff --git a/examples/async/groupsMethodsAsync.py b/examples/async/groupsMethodsAsync.py index 476ea80..7b03f77 100644 --- a/examples/async/groupsMethodsAsync.py +++ b/examples/async/groupsMethodsAsync.py @@ -7,8 +7,8 @@ async def main(): tasks = [ - greenAPI.groups.createGroupAsync("SDK Python", ["11001234567@c.us", "11001234568@c.us"]), - greenAPI.groups.addGroupParticipantAsync("1234567890@g.us", "11001234567@c.us"), + greenAPI.groups.createGroupAsync("SDK Python", ["79876543210@c.us", "11001234568@c.us"]), + greenAPI.groups.addGroupParticipantAsync("1234567890@g.us", "79876543210@c.us"), greenAPI.groups.getGroupDataAsync("1234567890@g.us") ] diff --git a/examples/async/payload.py b/examples/async/payload.py index a710e9b..d6ef90d 100644 --- a/examples/async/payload.py +++ b/examples/async/payload.py @@ -4,7 +4,7 @@ class GreenAPIDemo: def __init__(self): self.greenAPI = API.GreenAPI("1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345") - self.test_chat = "11001234567@c.us" + self.test_chat = "79876543210@c.us" async def run_demo(self): tasks = [ @@ -48,7 +48,7 @@ async def demo_contacts(self): for i, contact in enumerate(contacts[:3]): print(f" {i+1}. {contact.get('name', 'No name')} - {contact.get('id')}") - test_numbers = [79001234567, 79001234568] + test_numbers = [79876543210, 79001234568] for number in test_numbers: response = await self.greenAPI.serviceMethods.checkWhatsappAsync(number) if response.code == 200: @@ -86,7 +86,7 @@ async def demo_sending_messages(self): print("Poll message sent: ", response.data) contact = { - "phoneContact": 79001234567, + "phoneContact": 79876543210, "firstName": "Jane", "lastName": "Doe" } @@ -98,7 +98,7 @@ async def demo_sending_messages(self): print("Contact message sent: ", response.data) response = await self.greenAPI.sending.sendLocationAsync( - "79001234567@c.us", + "79876543210@c.us", 44.9370129, 89.8728409, "Restaurant", diff --git a/examples/async/sendTypingAsync.py b/examples/async/sendTypingAsync.py new file mode 100644 index 0000000..e6f1b4d --- /dev/null +++ b/examples/async/sendTypingAsync.py @@ -0,0 +1,14 @@ +import asyncio +from whatsapp_api_client_python import API + +greenAPI = API.GreenAPI( + "1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345" +) + +async def main(): + response = await greenAPI.serviceMethods.sendTypingAsync("79876543210@c.us", 5000, "recording") + if response.code == 200: + print(response.data) + +if __name__ == '__main__': + asyncio.run(main()) \ No newline at end of file diff --git a/examples/async/sending/sendFileByUploadAsync.py b/examples/async/sending/sendFileByUploadAsync.py index e875219..bca2ac0 100644 --- a/examples/async/sending/sendFileByUploadAsync.py +++ b/examples/async/sending/sendFileByUploadAsync.py @@ -12,10 +12,12 @@ async def main(): print(f"File {file_path} not found") else: response = await greenAPI.sending.sendFileByUploadAsync( - "11001234567@c.us", + "79876543210@c.us", file_path, "logo.jpg", - "logo" + "logo", + typingTime=5000, + typingType="recording" ) if response.code == 200: print(response.data) diff --git a/examples/async/sending/sendFileByUrlAsync.py b/examples/async/sending/sendFileByUrlAsync.py index 0f8c2f2..0ac5bfe 100644 --- a/examples/async/sending/sendFileByUrlAsync.py +++ b/examples/async/sending/sendFileByUrlAsync.py @@ -7,7 +7,7 @@ async def main(): response = await greenAPI.sending.sendFileByUrlAsync( - "11001234567@c.us", + "79876543210@c.us", "https://download.samplelib.com/png/sample-clouds2-400x300.png", "sample-clouds2-400x300.png", "Sample PNG" diff --git a/examples/async/sending/sendInteractiveButtonsAsync.py b/examples/async/sending/sendInteractiveButtonsAsync.py index c05400b..d44aa45 100644 --- a/examples/async/sending/sendInteractiveButtonsAsync.py +++ b/examples/async/sending/sendInteractiveButtonsAsync.py @@ -7,13 +7,13 @@ async def main(): response = await greenAPI.sending.sendInteractiveButtonsAsync( - "79001234567@c.us", + "79876543210@c.us", "This is message with buttons!", [{ "type": "call", "buttonId": "1", "buttonText": "Call me", - "phoneNumber": "79001234567" + "phoneNumber": "79876543210" }, { "type": "url", diff --git a/examples/async/sending/sendInteractiveButtonsReplyAsync.py b/examples/async/sending/sendInteractiveButtonsReplyAsync.py index 5d40fe7..ec21b0b 100644 --- a/examples/async/sending/sendInteractiveButtonsReplyAsync.py +++ b/examples/async/sending/sendInteractiveButtonsReplyAsync.py @@ -7,7 +7,7 @@ async def main(): response = await greenAPI.sending.sendInteractiveButtonsReplyAsync( - "79001234567@c.us", + "79876543210@c.us", "This is message with buttons!", [{ "buttonId": "1", diff --git a/examples/async/sending/sendLocationAsync.py b/examples/async/sending/sendLocationAsync.py index 9d55ebe..f88a594 100644 --- a/examples/async/sending/sendLocationAsync.py +++ b/examples/async/sending/sendLocationAsync.py @@ -7,7 +7,7 @@ async def main(): response = await greenAPI.sending.sendLocationAsync( - "79001234567@c.us", + "79876543210@c.us", 44.9370129, 89.8728409, "Restaurant", diff --git a/examples/async/sending/sendMessageAsync.py b/examples/async/sending/sendMessageAsync.py index 489c04d..901bc2c 100644 --- a/examples/async/sending/sendMessageAsync.py +++ b/examples/async/sending/sendMessageAsync.py @@ -6,7 +6,7 @@ ) async def main(): - response = await greenAPI.sending.sendMessageAsync("11001234567@c.us", "I use Green-API to send this message to you!") + response = await greenAPI.sending.sendMessageAsync("79876543210@c.us", "I use Green-API to send this message to you!", typingTime=5000) if response.code == 200: print(response.data) diff --git a/examples/async/sending/sendPollAsync.py b/examples/async/sending/sendPollAsync.py index a8fe119..fd43e6e 100644 --- a/examples/async/sending/sendPollAsync.py +++ b/examples/async/sending/sendPollAsync.py @@ -7,7 +7,7 @@ async def main(): response = await greenAPI.sending.sendPollAsync( - "11001234567@c.us", + "79876543210@c.us", "Please choose a color:", [ {"optionName": "Red"}, diff --git a/examples/async/sending/uploadFileAndSendFileByUrlAsync.py b/examples/async/sending/uploadFileAndSendFileByUrlAsync.py index cca9aea..2613998 100644 --- a/examples/async/sending/uploadFileAndSendFileByUrlAsync.py +++ b/examples/async/sending/uploadFileAndSendFileByUrlAsync.py @@ -23,7 +23,7 @@ async def main(): file_name = os.path.basename(url.path) send_file_response = await greenAPI.sending.sendFileByUrlAsync( - "11001234567@c.us", url_file, file_name + "79876543210@c.us", url_file, file_name ) if send_file_response.code == 200: diff --git a/examples/async/serviceMethodsAsync.py b/examples/async/serviceMethodsAsync.py index 5e108ae..2733a52 100644 --- a/examples/async/serviceMethodsAsync.py +++ b/examples/async/serviceMethodsAsync.py @@ -7,11 +7,11 @@ async def main(): tasks = [ - greenAPI.serviceMethods.checkWhatsappAsync(79001234567), + greenAPI.serviceMethods.checkWhatsappAsync(79876543210), greenAPI.serviceMethods.getContactsAsync(), - greenAPI.serviceMethods.deleteMessageAsync("11001234567@c.us", "BAE52A7F04F452F9", True), - greenAPI.serviceMethods.deleteMessageAsync("11001234567@c.us", "BAE52A7F04F452F9"), - greenAPI.serviceMethods.editMessageAsync("11001234567@c.us", "BAE5F793F61411D0", "Edited message text") + greenAPI.serviceMethods.deleteMessageAsync("79876543210@c.us", "BAE52A7F04F452F9", True), + greenAPI.serviceMethods.deleteMessageAsync("79876543210@c.us", "BAE52A7F04F452F9"), + greenAPI.serviceMethods.editMessageAsync("79876543210@c.us", "BAE5F793F61411D0", "Edited message text") ] responses = await asyncio.gather(*tasks, return_exceptions=True) diff --git a/examples/sync/createGroupAndSendMessage.py b/examples/sync/createGroupAndSendMessage.py index e9769fb..a2895d1 100644 --- a/examples/sync/createGroupAndSendMessage.py +++ b/examples/sync/createGroupAndSendMessage.py @@ -7,7 +7,7 @@ def main(): create_group_response = greenAPI.groups.createGroup( - "Group Name", ["11001234567@c.us", "11001234567@c.us"] + "Group Name", ["79876543210@c.us", "79876543210@c.us"] ) if create_group_response.code == 200: print(create_group_response.data) diff --git a/examples/sync/sendTyping.py b/examples/sync/sendTyping.py new file mode 100644 index 0000000..a71ddef --- /dev/null +++ b/examples/sync/sendTyping.py @@ -0,0 +1,15 @@ +from whatsapp_api_client_python import API + +greenAPI = API.GreenAPI( + "1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345" +) + + +def main(): + response = greenAPI.serviceMethods.sendTyping("79876543210@c.us", 5000, "recording") + + print(response.data) + + +if __name__ == '__main__': + main() diff --git a/examples/sync/sending/sendInteractiveButtons.py b/examples/sync/sending/sendInteractiveButtons.py index 8f4c7cb..0df7775 100644 --- a/examples/sync/sending/sendInteractiveButtons.py +++ b/examples/sync/sending/sendInteractiveButtons.py @@ -6,13 +6,13 @@ def main(): response = greenAPI.sending.sendInteractiveButtons( - "79001234567@c.us", + "79876543210@c.us", "This is message with buttons!", [{ "type": "call", "buttonId": "1", "buttonText": "Call me", - "phoneNumber": "79001234567" + "phoneNumber": "79876543210" }, { "type": "url", diff --git a/examples/sync/sending/sendInteractiveButtonsReply.py b/examples/sync/sending/sendInteractiveButtonsReply.py index fb712dc..d66b7ed 100644 --- a/examples/sync/sending/sendInteractiveButtonsReply.py +++ b/examples/sync/sending/sendInteractiveButtonsReply.py @@ -6,7 +6,7 @@ def main(): response = greenAPI.sending.sendInteractiveButtonsReply( - "79001234567@c.us", + "79876543210@c.us", "This is message with buttons!", [{ "buttonId": "1", diff --git a/examples/sync/sending/sendPictureByLink.py b/examples/sync/sending/sendPictureByLink.py index 241b860..e7f7520 100644 --- a/examples/sync/sending/sendPictureByLink.py +++ b/examples/sync/sending/sendPictureByLink.py @@ -7,7 +7,7 @@ def main(): response = greenAPI.sending.sendFileByUrl( - "11001234567@c.us", + "79876543210@c.us", "https://download.samplelib.com/png/sample-clouds2-400x300.png", "sample-clouds2-400x300.png", "Sample PNG" diff --git a/examples/sync/sending/sendPictureByUpload.py b/examples/sync/sending/sendPictureByUpload.py index 00532f5..1d43ceb 100644 --- a/examples/sync/sending/sendPictureByUpload.py +++ b/examples/sync/sending/sendPictureByUpload.py @@ -7,10 +7,12 @@ def main(): response = greenAPI.sending.sendFileByUpload( - "11001234567@c.us", + "79876543210@c.us", "data/logo.jpg", "logo.jpg", - "Available rates" + "Available rates", + typingTime=5000, + typingType="recording" ) print(response.data) diff --git a/examples/sync/sending/sendPoll.py b/examples/sync/sending/sendPoll.py index 1f8c97d..7cfbab9 100644 --- a/examples/sync/sending/sendPoll.py +++ b/examples/sync/sending/sendPoll.py @@ -7,7 +7,7 @@ def main(): response = greenAPI.sending.sendPoll( - "11001234567@c.us", + "79876543210@c.us", "Please choose a color:", [ {"optionName": "Red"}, diff --git a/examples/sync/sending/sendTextMessage.py b/examples/sync/sending/sendTextMessage.py index 221f46d..daeef26 100644 --- a/examples/sync/sending/sendTextMessage.py +++ b/examples/sync/sending/sendTextMessage.py @@ -6,7 +6,7 @@ def main(): - response = greenAPI.sending.sendMessage("11001234567@c.us", "Message text") + response = greenAPI.sending.sendMessage("79876543210@c.us", "Message text", typingTime=5000) print(response.data) diff --git a/examples/sync/sending/uploadFileAndSendFileByUrl.py b/examples/sync/sending/uploadFileAndSendFileByUrl.py index abfd096..494d6bd 100644 --- a/examples/sync/sending/uploadFileAndSendFileByUrl.py +++ b/examples/sync/sending/uploadFileAndSendFileByUrl.py @@ -21,7 +21,7 @@ def main(): file_name = basename(url.path) send_file_by_url_response = greenAPI.sending.sendFileByUrl( - "11001234567@c.us", url_file, file_name + "79876543210@c.us", url_file, file_name ) if send_file_by_url_response.code == 200: print(send_file_by_url_response.data) diff --git a/examples/sync/serviceMethods.py b/examples/sync/serviceMethods.py index 7149b09..c5fdd89 100644 --- a/examples/sync/serviceMethods.py +++ b/examples/sync/serviceMethods.py @@ -7,13 +7,13 @@ def main(): # DeleteMessage for sender - response = greenAPI.serviceMethods.deleteMessage("11001234567@c.us", "BAE52A7F04F452F9", True) + response = greenAPI.serviceMethods.deleteMessage("79876543210@c.us", "BAE52A7F04F452F9", True) # DeleteMessage for all (default) - response = greenAPI.serviceMethods.deleteMessage("11001234567@c.us", "BAE5558FFC7565C2") + response = greenAPI.serviceMethods.deleteMessage("79876543210@c.us", "BAE5558FFC7565C2") # EditMessage - response = greenAPI.serviceMethods.editMessage("11001234567@c.us", "BAE5F793F61411D0", "New text") + response = greenAPI.serviceMethods.editMessage("79876543210@c.us", "BAE5F793F61411D0", "New text") print(response.data) # new idMessage if __name__ == '__main__': diff --git a/whatsapp_api_client_python/tools/sending.py b/whatsapp_api_client_python/tools/sending.py index 3372d81..cdea029 100644 --- a/whatsapp_api_client_python/tools/sending.py +++ b/whatsapp_api_client_python/tools/sending.py @@ -20,7 +20,8 @@ def sendMessage( message: str, quotedMessageId: Optional[str] = None, archiveChat: Optional[bool] = None, - linkPreview: Optional[bool] = None + linkPreview: Optional[bool] = None, + typingTime: Optional[int] = None ) -> Response: """ The method is aimed for sending a text message to a personal or @@ -44,7 +45,8 @@ async def sendMessageAsync( message: str, quotedMessageId: Optional[str] = None, archiveChat: Optional[bool] = None, - linkPreview: Optional[bool] = None + linkPreview: Optional[bool] = None, + typingTime: Optional[int] = None ) -> Response: request_body = self.__handle_parameters(locals()) @@ -143,7 +145,9 @@ def sendFileByUpload( path: str, fileName: Optional[str] = None, caption: Optional[str] = None, - quotedMessageId: Optional[str] = None + quotedMessageId: Optional[str] = None, + typingTime: Optional[int] = None, + typingType: Optional[str] = None ) -> Response: """ The method is aimed for sending a file uploaded by form @@ -174,7 +178,9 @@ async def sendFileByUploadAsync( path: str, fileName: Optional[str] = None, caption: Optional[str] = None, - quotedMessageId: Optional[str] = None + quotedMessageId: Optional[str] = None, + typingTime: Optional[int] = None, + typingType: Optional[str] = None ) -> Response: request_body = self.__handle_parameters(locals()) @@ -201,7 +207,9 @@ def sendFileByUrl( fileName: str, caption: Optional[str] = None, quotedMessageId: Optional[str] = None, - archiveChat: Optional[bool] = None + archiveChat: Optional[bool] = None, + typingTime: Optional[int] = None, + typingType: Optional[str] = None ) -> Response: """ The method is aimed for sending a file uploaded by URL. @@ -225,7 +233,9 @@ async def sendFileByUrlAsync( fileName: str, caption: Optional[str] = None, quotedMessageId: Optional[str] = None, - archiveChat: Optional[bool] = None + archiveChat: Optional[bool] = None, + typingTime: Optional[int] = None, + typingType: Optional[str] = None ) -> Response: request_body = self.__handle_parameters(locals()) @@ -281,7 +291,8 @@ def sendLocation( longitude: float, nameLocation: Optional[str] = None, address: Optional[str] = None, - quotedMessageId: Optional[str] = None + quotedMessageId: Optional[str] = None, + typingTime: Optional[int] = None ) -> Response: """ The method is aimed for sending location message. @@ -305,7 +316,8 @@ async def sendLocationAsync( longitude: float, nameLocation: Optional[str] = None, address: Optional[str] = None, - quotedMessageId: Optional[str] = None + quotedMessageId: Optional[str] = None, + typingTime: Optional[int] = None ) -> Response: request_body = self.__handle_parameters(locals()) @@ -319,7 +331,8 @@ def sendContact( self, chatId: str, contact: Dict[str, Union[int, str]], - quotedMessageId: Optional[str] = None + quotedMessageId: Optional[str] = None, + typingTime: Optional[int] = None ) -> Response: """ The method is aimed for sending a contact message. @@ -340,7 +353,8 @@ async def sendContactAsync( self, chatId: str, contact: Dict[str, Union[int, str]], - quotedMessageId: Optional[str] = None + quotedMessageId: Optional[str] = None, + typingTime: Optional[int] = None ) -> Response: request_body = self.__handle_parameters(locals()) @@ -400,7 +414,8 @@ async def forwardMessagesAsync( self, chatId: str, chatIdFrom: str, - messages: List[str] + messages: List[str], + typingTime: Optional[int] = None ) -> Response: request_body = self.__handle_parameters(locals()) @@ -416,7 +431,8 @@ def sendPoll( message: str, options: List[Dict[str, str]], multipleAnswers: Optional[bool] = None, - quotedMessageId: Optional[str] = None + quotedMessageId: Optional[str] = None, + typingTime: Optional[int] = None ) -> Response: """ This method is intended for sending messages with a poll to a @@ -440,7 +456,8 @@ async def sendPollAsync( message: str, options: List[Dict[str, str]], multipleAnswers: Optional[bool] = None, - quotedMessageId: Optional[str] = None + quotedMessageId: Optional[str] = None, + typingTime: Optional[int] = None ) -> Response: request_body = self.__handle_parameters(locals()) @@ -457,6 +474,7 @@ def sendInteractiveButtons( buttons: List[Dict[str, Union[str, Dict[str, str]]]], header: Optional[str] = None, footer: Optional[str] = None, + typingTime: Optional[int] = None, ) -> Response: """ The method is used to send a message with buttons to personal chats. @@ -480,6 +498,7 @@ async def sendInteractiveButtonsAsync( buttons: List[Dict[str, Union[str, Dict[str, str]]]], header: Optional[str] = None, footer: Optional[str] = None, + typingTime: Optional[int] = None ) -> Response: request_body = self.__handle_parameters(locals()) @@ -497,6 +516,7 @@ def sendInteractiveButtonsReply( buttons: List[Dict[str, str]], header: Optional[str] = None, footer: Optional[str] = None, + typingTime: Optional[int] = None ) -> Response: """ The method is used to send a message with buttons to personal chats. @@ -520,6 +540,7 @@ async def sendInteractiveButtonsReplyAsync( buttons: List[Dict[str, str]], header: Optional[str] = None, footer: Optional[str] = None, + typingTime: Optional[int] = None ) -> Response: request_body = self.__handle_parameters(locals()) diff --git a/whatsapp_api_client_python/tools/serviceMethods.py b/whatsapp_api_client_python/tools/serviceMethods.py index 43b7b7e..7431e45 100644 --- a/whatsapp_api_client_python/tools/serviceMethods.py +++ b/whatsapp_api_client_python/tools/serviceMethods.py @@ -258,4 +258,43 @@ async def setDisappearingChatAsync( "POST", "{{host}}/waInstance{{idInstance}}/setDisappearingChat/{{apiTokenInstance}}", request_body + ) + + def sendTyping( + self, chatId: str, typingTime: Optional[int] = None, typingType: Optional[str] = None, + ) -> Response: + """ + The method is used to send a notification about typing or recording audio in a chat. + + https://green-api.com/en/docs/api/service/SendTyping/ + """ + + request_body = locals() + if typingTime is None: + request_body.pop("typingTime") + if typingType is None: + request_body.pop("typingType") + request_body.pop("self") + + return self.api.request( + "POST", ( + "{{host}}/waInstance{{idInstance}}/" + "sendTyping/{{apiTokenInstance}}" + ), request_body + ) + + async def sendTypingAsync( + self, chatId: str, typingTime: Optional[int] = None, typingType: Optional[str] = None, + ) -> Response: + request_body = locals() + if typingTime is None: + request_body.pop("typingTime") + if typingType is None: + request_body.pop("typingType") + request_body.pop("self") + + return await self.api.requestAsync( + "POST", + "{{host}}/waInstance{{idInstance}}/sendTyping/{{apiTokenInstance}}", + request_body ) \ No newline at end of file From ec7c405e160366c91befef87e5ed868e75daf94b Mon Sep 17 00:00:00 2001 From: Ash <165753515+AshLeigh-Fraxinus@users.noreply.github.com> Date: Mon, 17 Nov 2025 11:16:39 +0300 Subject: [PATCH 2/2] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c807611..7eb849d 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="whatsapp-api-client-python", - version="0.0.52", + version="0.0.53", description=( "This library helps you easily create" " a Python application with WhatsApp API."