Skip to content

Commit 301b0d5

Browse files
committed
fix mimetypes
1 parent e13aed9 commit 301b0d5

6 files changed

Lines changed: 17 additions & 40 deletions

File tree

examples/receiveNotification.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from datetime import datetime
33
import json
44
from whatsapp_api_client_python import greenAPI as greenAPI
5-
from whatsapp_api_client_python.tools.webhooks import TypeWebhook as TypeWebhook
65

76

87
ID_INSTANCE = environ['ID_INSTANCE']
@@ -14,23 +13,21 @@ def main():
1413
restApi.webhooks.startReceivingNotifications(onEvent)
1514

1615
def onEvent(typeWebhook, body):
17-
if typeWebhook == TypeWebhook.INCOMING_MESSAGE_RECEIVED.value:
16+
if typeWebhook == 'incomingMessageReceived':
1817
onIncomingMessageReceived(body)
19-
elif typeWebhook == TypeWebhook.DEVICE_INFO.value:
18+
elif typeWebhook == 'deviceInfo':
2019
onDeviceInfo(body)
21-
elif typeWebhook == TypeWebhook.INCOMING_CALL.value:
20+
elif typeWebhook == 'incomingCall':
2221
onIncomingCall(body)
23-
elif typeWebhook == TypeWebhook.INCOMING_MESSAGE_RECEIVED.value:
24-
onIncomingMessageReceived(body)
25-
elif typeWebhook == TypeWebhook.OUTGOING_API_MESSAGE_RECEIVED.value:
22+
elif typeWebhook == 'outgoingAPIMessageReceived':
2623
onOutgoingAPIMessageReceived(body)
27-
elif typeWebhook == TypeWebhook.OUTGOING_MESSAGE_RECEIVED.value:
24+
elif typeWebhook == 'outgoingMessageReceived':
2825
onOutgoingMessageReceived(body)
29-
elif typeWebhook == TypeWebhook.OUTGOING_MESSAGE_STATUS.value:
26+
elif typeWebhook == 'outgoingMessageStatus':
3027
onOutgoingMessageStatus(body)
31-
elif typeWebhook == TypeWebhook.STATE_INSTANCE_CHANGED.value:
28+
elif typeWebhook == 'stateInstanceChanged':
3229
onStateInstanceChanged(body)
33-
elif typeWebhook == TypeWebhook.STATUS_INSTANCE_CHANGED.value:
30+
elif typeWebhook == 'statusInstanceChanged':
3431
onStatusInstanceChanged(body)
3532

3633
def onIncomingMessageReceived(body):

examples/sendPictureByUpload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
restApi = greenAPI.RestApi(ID_INSTANCE, API_TOKEN_INSTANCE)
99

1010
def main():
11-
result = restApi.sending.sendFileByUpload('79001234567@c.us',
11+
result = restApi.sending.sendFileByUpload('77073450985@c.us',
1212
'C:\Games\PicFromDisk.png',
1313
'PicFromDisk.png', 'Picture from disk')
1414
print(result.data)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="whatsapp-api-client-python",
8-
version="0.0.20",
8+
version="0.0.21",
99
install_requires=['requests'],
1010
author="Ivan Sadovy",
1111
author_email="sadiv@bk.ru",

whatsapp_api_client_python/greenAPI.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from array import array
2+
import mimetypes
23
import requests
34
import json
45
from whatsapp_api_client_python.response import Response
@@ -14,6 +15,7 @@
1415
from whatsapp_api_client_python.tools.serviceMethods import ServiceMethods
1516
from whatsapp_api_client_python.tools.webhooks import Webhooks
1617

18+
1719
class RestApi:
1820
'REST API class'
1921

@@ -57,7 +59,7 @@ def request(self, method: str, url: str,
5759
}
5860
payloadData = json.dumps(payload)
5961
else:
60-
payloadData = payload
62+
payloadData = payload
6163
result = requests.request(method, url, headers = headers,
6264
data = payloadData,
6365
files = files)

whatsapp_api_client_python/tools/sending.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from array import array
22
import os.path
3+
import mimetypes
34
from whatsapp_api_client_python.response import Response
45

56

@@ -77,8 +78,10 @@ def sendFileByUpload(self, chatId: str, path: str,
7778
if fileName == None:
7879
fileName = pathParts[pathParts.count - 1]
7980

81+
mimeType = mimetypes.guess_type(path)[0]
82+
8083
files = [
81-
('file', open(path,'rb'))
84+
('file', (fileName, open(path,'rb'), mimeType))
8285
]
8386

8487
requestBody = {

whatsapp_api_client_python/tools/webhooks.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
1-
from whatsapp_api_client_python.response import Response
2-
from enum import Enum
3-
4-
5-
class TypeWebhook(Enum):
6-
INCOMING_MESSAGE_RECEIVED = 'incomingMessageReceived'
7-
OUTGOING_MESSAGE_RECEIVED = 'outgoingMessageReceived'
8-
OUTGOING_API_MESSAGE_RECEIVED = 'outgoingAPIMessageReceived'
9-
OUTGOING_MESSAGE_STATUS = 'outgoingMessageStatus'
10-
STATE_INSTANCE_CHANGED = 'stateInstanceChanged'
11-
STATUS_INSTANCE_CHANGED = 'statusInstanceChanged'
12-
DEVICE_INFO = 'deviceInfo'
13-
INCOMING_CALL = 'incomingCall'
14-
15-
class TypeMessage(Enum):
16-
TEXT_MESSAGE = 'textMessage'
17-
IMAGE_MESSAGE = 'imageMessage'
18-
VIDEO_MESSAGE = 'videoMessage'
19-
DOCUMENT_MESSAGE = 'documentMessage'
20-
AUDIO_MESSAGE = 'audioMessage'
21-
LOCATION_MESSAGE = 'locationMessage'
22-
CONTACT_MESSAGE = 'contactMessage'
23-
EXTENDED_TEXT_MESSAGE = 'extendedTextMessage'
24-
QUOTED_MESSAGE = 'quotedMessage'
25-
261
class Webhooks:
272
def __init__(self, restApi) -> None:
283
self.restApi = restApi

0 commit comments

Comments
 (0)