Skip to content

Commit 372160b

Browse files
Merge pull request #74 from green-api/SW-3445
SW-3445: Требуется разработать асинхронную библиотеку
1 parent 731b8f6 commit 372160b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1543
-82
lines changed

.github/workflows/python-package.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ on:
1111
jobs:
1212
build:
1313
name: ${{ matrix.python-version }}
14-
runs-on: ubuntu-20.04
14+
runs-on: ubuntu-24.04
1515
strategy:
1616
matrix:
17-
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12" ]
17+
python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
1818

1919
steps:
2020
- uses: actions/checkout@v3

README.md

Lines changed: 76 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,31 @@ greenAPI = API.GreenAPI(
5858

5959
### Sending a text message to a WhatsApp number
6060

61-
Link to example: [sendTextMessage.py](
62-
https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendTextMessage.py
63-
).
61+
Link to example: [sendTextMessage.py](./examples/sync/sendTextMessage.py).
6462

6563
```
6664
response = greenAPI.sending.sendMessage("11001234567@c.us", "Message text")
6765
6866
print(response.data)
6967
```
7068

69+
### Sending a text message asynchronously
70+
71+
Link to example: [sendMessageAsync.py](./examples/async/sending/sendMessageAsync.py).
72+
73+
```
74+
import asyncio
75+
76+
async def main():
77+
response = await greenAPI.sending.sendMessageAsync("11001234567@c.us", "Message text")
78+
print(response.data)
79+
80+
asyncio.run(main())
81+
```
82+
7183
### Sending an image via URL
7284

73-
Link to example: [sendPictureByLink.py](
74-
https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPictureByLink.py
75-
).
85+
Link to example: [sendPictureByLink.py](./examples/sync/sendPictureByLink.py).
7686

7787
```
7888
response = greenAPI.sending.sendFileByUrl(
@@ -87,29 +97,44 @@ print(response.data)
8797

8898
### Sending an image by uploading from the disk
8999

90-
Link to example: [sendPictureByUpload.py](
91-
https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPictureByUpload.py
92-
).
100+
Link to example: [sendPictureByUpload.py](./examples/sync/sendPictureByUpload.py).
93101

94102
```
95103
response = greenAPI.sending.sendFileByUpload(
96104
"11001234567@c.us",
97-
"data/rates.png",
98-
"rates.png",
105+
"data/logo.jpg",
106+
"logo.jpg",
99107
"Available rates"
100108
)
101109
102110
print(response.data)
103111
```
104112

113+
### Sending an image asynchronously by uploading from the disk
114+
115+
Link to example: [sendFileByUploadAsync.py](./examples/async/sending/sendFileByUploadAsync.py).
116+
117+
```
118+
import asyncio
119+
120+
async def main():
121+
response = await greenAPI.sending.sendFileByUploadAsync(
122+
"11001234567@c.us",
123+
"data/logo.jpg",
124+
"logo.jpg",
125+
"Available rates"
126+
)
127+
print(response.data)
128+
129+
asyncio.run(main())
130+
```
131+
105132
### Group creation and sending a message to the group
106133

107134
**Attention**. If one tries to create a group with a non-existent number, WhatsApp may block the sender's number. The
108135
number in the example is non-existent.
109136

110-
Link to example: [createGroupAndSendMessage.py](
111-
https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/createGroupAndSendMessage.py
112-
).
137+
Link to example: [createGroupAndSendMessage.py](./examples/sync/createGroupAndSendMessage.py).
113138

114139
```
115140
create_group_response = greenAPI.groups.createGroup(
@@ -123,9 +148,7 @@ if create_group_response.code == 200:
123148

124149
### Receive incoming messages by HTTP API
125150

126-
Link to example: [receiveNotification.py](
127-
https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/receiveNotification.py
128-
).
151+
Link to example: [receiveNotification.py](./examples/sync/receiveNotification.py).
129152

130153
The general concept of receiving data in the GREEN API is described [here](
131154
https://green-api.com/en/docs/api/receiving/
@@ -142,18 +165,27 @@ onEvent - your function which should contain parameters:
142165
| typeWebhook | received notification type (str) |
143166
| body | notification body (dict) |
144167

145-
Notification body types and formats can be found [here](
146-
https://green-api.com/en/docs/api/receiving/notifications-format/
147-
).
168+
Notification body types and formats can be found [here](https://green-api.com/en/docs/api/receiving/notifications-format/).
148169

149170
This method will be called when an incoming notification is received. Next, process notifications according to the
150171
business logic of your system.
151172

173+
### Receive incoming messages asynchronously by HTTP API
174+
175+
Link to example: [receiveNotificationAsync.py](./examples/async/receiveNotificationAsync.py).
176+
177+
```
178+
import asyncio
179+
180+
async def main():
181+
await greenAPI.webhooks.startReceivingNotificationsAsync(onEvent)
182+
183+
asyncio.run(main())
184+
```
185+
152186
### Sending a polling message
153187

154-
Link to example: [sendPoll.py](
155-
https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPoll.py
156-
).
188+
Link to example: [sendPoll.py](./examples/sync/sendPoll.py).
157189

158190
```
159191
response = greenAPI.sending.sendPoll(
@@ -171,7 +203,7 @@ print(response.data)
171203

172204
### Sending a text status
173205

174-
Link to example: [sendTextStatus.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/statusesMethods/sendTextStatus.py).
206+
Link to example: [sendTextStatus.py](./examples/sync/statusesMethods/sendTextStatus.py).
175207

176208
```
177209
response = greenAPI.statuses.sendTextStatus(
@@ -185,16 +217,24 @@ print(response.data)
185217

186218
## Examples list
187219

188-
| Description | Module |
189-
|----------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
190-
| Example of sending text | [sendTextMessage.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendTextMessage.py) |
191-
| Example of sending a picture by URL | [sendPictureByLink.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPictureByLink.py) |
192-
| Example of sending a picture by uploading from the disk | [sendPictureByUpload.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPictureByUpload.py) |
193-
| Example of a group creation and sending a message to the group | [createGroupAndSendMessage.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/createGroupAndSendMessage.py) |
194-
| Example of incoming webhooks receiving | [receiveNotification.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/receiveNotification.py) |
195-
| Example of sending a polling message | [sendPoll.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPoll.py) |
196-
| Example of sending a text status | [sendTextStatus.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/statusesMethods/sendTextStatus.py) |
197-
| Example of creating instance | [CreateInstance.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/partherMethods/CreateInstance.py) |
220+
| Description | Module |
221+
|----------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|
222+
| Example of sending text | [sendTextMessage.py](./examples/sync/sendTextMessage.pyy) |
223+
| Example of sending text asynchronously | [sendTextMessageAsync.py](./examples/async/sendMessageAsync.py) |
224+
| Example of sending a picture by URL | [sendPictureByLink.py](./examples/sync/sendPictureByLink.py) |
225+
| Example of sending a file by URL asynchronously | [sendFileByUrlAsync.py](./examples/async/sending/sendFileByUrlAsync.py) |
226+
| Example of sending a picture by uploading from the disk | [sendPictureByUpload.py](./examples/sync/sendPictureByUpload.py) |
227+
| Example of sending file by uploading from the disk asynchronously | [sendFileByUploadAsync.py](./examples/async/sending/sendFileByUploadAsync.py) |
228+
| Example of a group creation and sending a message to the group | [createGroupAndSendMessage.py](./examples/sync/createGroupAndSendMessage.py) |
229+
| Example of a group creation and sending a message to the group asynchronously | [createGroupAndSendMessageAsync.py](./examples/async/createGroupAndSendMessageAsync.py) |
230+
| Example of incoming webhooks receiving | [receiveNotification.py](./examples/sync/receiveNotification.py) |
231+
| Example of incoming webhooks receiving asynchronously | [receiveNotificationAsync.py](./examples/async/receiveNotificationAsync.py) |
232+
| Example of sending a polling message | [sendPoll.py](./examples/sync/sendPoll.py) |
233+
| Example of sending a polling message asynchronously | [sendPollAsync.py](./examples/async/sending/sendPollasync.py) |
234+
| Example of sending a text status | [sendTextStatus.py](./examples/sync/statusesMethods/sendTextStatus.py) |
235+
| Example of sending a text status asynchronously | [sendTextStatusAsync.py](./examples/async/statusesMethods/sendTextStatusAsync.py) |
236+
| Example of creating instance | [CreateInstance.py](./examples/sync/partherMethods/CreateInstance.py) |
237+
| Example of creating instance asynchronously | [CreateInstanceAsync.py](./examples/async/partherMethods/CreateInstanceAsync.py) |
198238

199239
## The full list of the library methods
200240

@@ -272,10 +312,9 @@ print(response.data)
272312
## External products
273313

274314
- [requests](https://requests.readthedocs.io/en/latest/) - for HTTP requests.
315+
- [aiohttp](https://docs.aiohttp.org/) - for async HTTP requests.
275316

276317
## License
277318

278-
Licensed under [
279-
Creative Commons Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0)
280-
](https://creativecommons.org/licenses/by-nd/4.0/) terms.
319+
Licensed under [Creative Commons Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0)](https://creativecommons.org/licenses/by-nd/4.0/) terms.
281320
Please see file [LICENSE](https://github.com/green-api/whatsapp-api-client-python/blob/master/LICENSE).

0 commit comments

Comments
 (0)