-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from OdyAsh/main
Handle WhatsApp Unsupported Msgs, Also: add new logger utility and refine .gitignore
- Loading branch information
Showing
18 changed files
with
326 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
docs/structure_of_api_responses/meta_whatsapp_structure_of_a_user_incoming_msg.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
{ | ||
"object": "whatsapp_business_account", | ||
"entry": [ | ||
{ | ||
"id": "<<unique numeric ID for this specific response>>", | ||
"changes": [ | ||
{ | ||
"value": { | ||
"messaging_product": "whatsapp", | ||
"metadata": { | ||
"display_phone_number": "<<the WHATSAPP_BUSINESS_PHONE_NUMBER without non-numeric characters (e.g., +1 (555) 555-5555 -> 15555555555)>>", | ||
"phone_number_id": "<<the WHATSAPP_BUSINESS_PHONE_NUMBER_ID (this ID is a numeric value)>>" | ||
}, | ||
"contacts": [ | ||
{ | ||
"profile": { | ||
"name": "<<the whatsapp sender's display name>>" | ||
}, | ||
"wa_id": "<<the whatsapp sender's phone number without non-numeric characters>>" | ||
} | ||
], | ||
"messages": [ | ||
{ | ||
"from": "<<the whatsapp sender's phone number without non-numeric characters>>", | ||
"id": "wamid.<<UNIQUE_NUMERIC_ID_FOR_THIS_SPECIFIC_MSG>>", | ||
"timestamp": "<<Unix timestamp of the message (e.g., 1730548169)>>", | ||
"type": "<<the type of the sent message ('text'/'audio'/'video'/'image'/'sticker'/'document'/'location'/'contacts'/'unsupported')>>", | ||
// The following field is only present if "type" has value "text" | ||
"text": { | ||
"body": "<<the whatsapp sender's sent message>>" | ||
}, | ||
// The following field is only present if "type" has value "audio" | ||
"audio": { | ||
"mime_type": "audio/ogg", | ||
"codecs": "opus", | ||
"sha256": "<<SHA256 hash of the audio file>>", | ||
"id": "<<unique numeric ID for this specific audio file>>", | ||
"voice": "True/False (actually sent as a boolean value, so no quotes)" | ||
}, | ||
// The following field is only present if "type" has value "image" | ||
"image": { | ||
"mime_type": "image/jpeg", | ||
"sha256": "<<SHA256 hash of the image file>>", | ||
"id": "<<unique numeric ID for this specific image file>>" | ||
}, | ||
// The following field is only present if "type" has value "sticker" | ||
"sticker": { | ||
"mime_type": "image/webp", | ||
"sha256": "<<SHA256 hash of the sticker file>>", | ||
"id": "<<unique numeric ID for this specific sticker file>>", | ||
"animated": "True/False (actually sent as a boolean value, so no quotes)" | ||
}, | ||
// The following field is only present if "type" has value "video" (when sending a video/gif) | ||
"video": { | ||
"mime_type": "video/mp4", | ||
"sha256": "<<SHA256 hash of the video file>>", | ||
"id": "<<unique numeric ID for this specific video file>>" | ||
}, | ||
// the following field is only present if "type" has value "document" | ||
"document": { | ||
"filename": "<<the name of the document file>>", | ||
"mime_type": "application/pdf , application/vnd.openxmlformats-officedocument.wordprocessingml.document , etc.", | ||
"sha256": "<<SHA256 hash of the document file>>", | ||
"id": "<<unique numeric ID for this specific document file>>" | ||
}, | ||
// the following field is only present if "type" has value "location" | ||
"location": { | ||
"address": "<<address of the location>>", | ||
"latitude": "<<latitude of the location>>", | ||
"longitude": "<<longitude of the location>>", | ||
"name": "<<name of the location>>", | ||
"url": "<<URL of the location (https://foursquare.com/v/LOCATION_ID)>>" | ||
}, | ||
// the following field is only present if "type" has value "contacts" | ||
"contacts":[ | ||
{ | ||
"name": { | ||
"first_name": "<<first name of the contact>>", | ||
"middle_name": "<<middle name of the contact>>", | ||
"last_name": "<<last name of the contact>>", | ||
"formatted_name": "<<formatted name of the contact (entire name)>>" | ||
}, | ||
"phones": [ | ||
{ | ||
"phone": "<<phone number of the contact (with spaces and special characters)>>", | ||
"wa_id": "<<phone number of the contact (without spaces and special characters)>>", | ||
"type": "<<type of the phone number (e.g., 'MOBILE', 'WORK', 'HOME', etc.)>>" | ||
} | ||
], | ||
} | ||
], | ||
// The following field is only present if "type" has value "unsupported" | ||
// as of 2024-11-12, video notes, gifs sent from giphy (whatsapp keyboard), and polls are not supported | ||
"errors": [ | ||
{ | ||
"code": 131051, | ||
"title": "Message type unknown", | ||
"message": "Message type unknown", | ||
"error_data": { | ||
"details": "Message type is currently not supported." | ||
} | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"field": "messages" | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import logging | ||
|
||
from ansari.config import get_settings | ||
|
||
|
||
def get_logger( | ||
caller_file_name: str, logging_level=None, debug_mode=None | ||
) -> logging.Logger: | ||
""" | ||
Creates and returns a logger instance for the specified caller file. | ||
Args: | ||
caller_file_name (str): The name of the file requesting the logger. | ||
logging_level (Optional[str]): The logging level to be set for the logger. | ||
If None, it defaults to the LOGGING_LEVEL from settings. | ||
debug_mode (Optional[bool]): If True, adds a console handler to the logger. | ||
If None, it defaults to the DEBUG_MODE from settings. | ||
Returns: | ||
logging.Logger: Configured logger instance. | ||
""" | ||
logger = logging.getLogger(caller_file_name) | ||
if logging_level is None: | ||
logging_level = get_settings().LOGGING_LEVEL.upper() | ||
logger.setLevel(logging_level) | ||
|
||
if debug_mode is not False and get_settings().DEBUG_MODE: | ||
console_handler = logging.StreamHandler() | ||
console_handler.setLevel(logging_level) | ||
logger.addHandler(console_handler) | ||
|
||
return logger |
Oops, something went wrong.