/
media.rst
77 lines (56 loc) 路 1.66 KB
/
media.rst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Sending Media Messages
======================
Sending media from URL
----------------------
.. code-block:: python
:caption: Media message from URL
:linenos:
from pywa import WhatsApp
wa = WhatsApp(phone_id='972123456789', token='xxxxx')
recipient = '972987654321'
# - From URL
wa.send_image(
to=recipient,
image='https://cdn.pixabay.com/photo/2014/10/01/10/44/animal-468228_1280.jpg'
)
Sending media from local file
-----------------------------
.. code-block:: python
:caption: Media message from local file
:linenos:
from pywa import WhatsApp
wa = WhatsApp(phone_id='972123456789', token='xxxxx')
recipient = '972987654321'
# - From local file
wa.send_video(
to=recipient,
video='/path/to/video.mp4'
)
Sending media from file id
--------------------------
.. code-block:: python
:caption: Media message from file id
:linenos:
from pywa import WhatsApp
wa = WhatsApp(phone_id='972123456789', token='xxxxx')
recipient = '972987654321'
audio_id = wa.upload_media(media='/path/to/audio.ogg', mime_type='audio/ogg')
wa.send_audio(
to=recipient,
audio=audio_id
)
Sending media from bytes
------------------------
.. code-block:: python
:caption: Media message from bytes
:linenos:
from pywa import WhatsApp
import requests
wa = WhatsApp(phone_id='972123456789', token='xxxxx')
recipient = '972987654321'
res = requests.get('https://cdn.pixabay.com/photo/2014/10/01/10/44/animal-468228_1280.jpg')
wa.send_document(
to=recipient,
document=res.content,
filename='animal.jpg'
)