diff --git a/utils_v2/goog/gmail/gmail_client.py b/utils_v2/goog/gmail/gmail_client.py index 708b233..ac2d327 100644 --- a/utils_v2/goog/gmail/gmail_client.py +++ b/utils_v2/goog/gmail/gmail_client.py @@ -140,6 +140,7 @@ class AsyncGMailClient(AsyncGoogleBase): DOCUMENTATION: 1. https://developers.google.com/gmail/api/reference/rest/v1/users/getProfile 2. https://developers.google.com/people/api/rest/v1/people/get + 3. https://developers.google.com/people/api/rest/v1/people#Person :param tokens: The object that holds the access token to the service. :param user_id: The id of the user for which this service must be run. Typically, the e-mail id itself or "me". :return: A structured response where the list of labels will be in the 'data' variable. @@ -164,11 +165,13 @@ class AsyncGMailClient(AsyncGoogleBase): if gmail_api_response.httpCode in [200]: gmail_api_response.success = True gmail_api_response.data = await gmail_api_response.get_json() + gmail_api_response.data["displayName"] = None + gmail_api_response.data["displayPictureUrl"] = None # Make the People API call: if not self._debug_only_errors: self._printer("Getting User Profile.") people_api_response = await self.get( - url = f"https://people.googleapis.com/v1/people/me", + url = f"https://people.googleapis.com/v1/people/me?personFields=names,photos,birthdays,phoneNumbers,genders,emailAddresses,addresses", headers = {"Authorization": f"Bearer {tokens.accessToken}"} ) @@ -176,10 +179,15 @@ class AsyncGMailClient(AsyncGoogleBase): if people_api_response.httpCode in [200]: people_api_response.success = True people_api_response.data = await people_api_response.get_json() - for k, v in gmail_api_response.data.items(): people_api_response.data[k] = v + for item in people_api_response.data.get("names", []): + if item["metadata"]["primary"]: + gmail_api_response.data["displayName"] = item.get("displayName") + for item in people_api_response.data.get("photos", []): + if item["metadata"]["primary"]: + gmail_api_response.data["displayPictureUrl"] = item.get("url") # Done here: - return people_api_response + return gmail_api_response # ┓ ┓ ┓ # ┃ ┏┓┣┓┏┓┃┏ @@ -911,11 +919,6 @@ if __name__ == "__main__": secrets_file = r"../../../creds/goog/app/google_tcaoff_test_oauth_20241125.json" secrets_dict = json.from_file(secrets_file) - # Read the user's tokens that will give you app access to that user's account: - tokens_file = r"../../../creds/goog/user/test_user_tokens_20241125.json" - tokens_dict = json.from_file(tokens_file) - test_tokens = GoogleAuthTokens(**tokens_dict) - async def main(): # Create an instance of the client: @@ -937,61 +940,14 @@ if __name__ == "__main__": )) # Get tokens from callback: - # print("TOKENS:", await my_gmail.get_authorization_tokens( - # redirect_url = r"https://api.thecaoffice.com/converse/mail/callback/gmail?state=User123-Bhopli..." - # )) - - # Create a sample mail: - my_mail = GMailMessage( - from_email = "pskhushal@gmail.com", - to_email = "orangebhopli@gmail.com", - subject = "Bhopli is the best! (Parts Sequence Test)", - cc_emails = None, - bcc_emails = None + test_tokens = await my_gmail.get_authorization_tokens( + scopes = SCOPES_GMAIL_MAIL_MANAGEMENT, + redirect_url = input("Paste the redirect URL here: ") ) - my_mail.add_html( - """ - - - - - Sample HTML String - - - -

Hello, Bhopli!

-

Bhopli is the best, most well-behaved cat in the known universe.

- - - """ - ) - my_mail.add_text("(3rd part - text) This is how you should pet her 👇") - my_mail.add_inline_image(r"../../../data/images/cat_petting.png") - my_mail.add_attachment(r"../../../data/pdf/sample_label.pdf") - # print(my_mail.get_raw_message(as_base64 = False)) + print("TOKENS:", test_tokens) # Test some feature: - # auth_url = await my_gmail.get_authorization_url( - # state = "1234567890", - # scopes = SCOPES_GMAIL_MAIL_MANAGEMENT, - # approval_prompt = "force", - # user_email = "pskhushal@gmail.com" - # ) - # print("AUTH URL:", auth_url) - # response = await my_gmail.list_labels( - # tokens = test_tokens, - # ) - # response = await my_gmail.get_message( - # tokens = test_tokens, - # message_id = "1936bfbfc912b86f" - # ) + response = await my_gmail.get_user_profile(tokens = test_tokens) print("SUCCESS:", response.success) print("SUMMARY:", response.to_markdown()) print("\n\n---\n\n") diff --git a/utils_v2/goog/models/data/auth_tokens.py b/utils_v2/goog/models/data/auth_tokens.py index 7b5d1d4..1873934 100644 --- a/utils_v2/goog/models/data/auth_tokens.py +++ b/utils_v2/goog/models/data/auth_tokens.py @@ -90,6 +90,8 @@ class GoogleAuthTokens(BaseModel): expiresAt: AwareDatetime = Field(description = "the time (utc) at which the token will expire") scopes: List[str] = Field(description = "the list of permissions", default = []) email: str | None = Field(description = "the email id of the user", default = None) + displayName: str | None = Field(description = "the display name of the user", default = None) + displayPictureUrl: str | None = Field(description = "the url to the display picture of the user", default = None) # ┏┓ ┏• # ┃ ┏┓┏┓╋┓┏┓ diff --git a/utils_v2/sms/nimbus/__init__.py b/utils_v2/sms/nimbus/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/utils_v2/sms/async_nimbus.py b/utils_v2/sms/nimbus/async_nimbus.py similarity index 96% rename from utils_v2/sms/async_nimbus.py rename to utils_v2/sms/nimbus/async_nimbus.py index 1d4b926..058d9f2 100644 --- a/utils_v2/sms/async_nimbus.py +++ b/utils_v2/sms/nimbus/async_nimbus.py @@ -79,6 +79,9 @@ class AsyncNimbusSMS: MESSAGE_TYPE_REGULAR = 0 MESSAGE_TYPE_UNICODE = 1 + MESSAGE_TYPE_NOT_FLASH = 0 + MESSAGE_TYPE_FLASH = 1 + def __init__( self, entity_id, @@ -147,7 +150,8 @@ class AsyncNimbusSMS: template_id, recipient_number, message, - message_type = MESSAGE_TYPE_REGULAR + message_type = MESSAGE_TYPE_REGULAR, + flash = MESSAGE_TYPE_NOT_FLASH ): """ @@ -160,6 +164,7 @@ class AsyncNimbusSMS: :param message: The message to send to the recipient. Should match the template that is being sent. :param message_type: Choose between 'AsyncNimbusSMS.MESSAGE_TYPE_REGULAR' (default) and 'AsyncNimbusSMS.MESSAGE_TYPE_UNICODE' based on the type of characters being sent. Both are class variables. + :param flash: to choose between a regular inbox SMS, or a flash SMS. :return: The dict of all the details of the message that was sent including whether, or not, it was successfully sent. Other details depend on the service provider (Nimbus IT in this case). """ @@ -173,7 +178,8 @@ class AsyncNimbusSMS: "message": message, "length": len(message), "template_id": template_id, - "raw": None + "raw": None, + "isFlash": True if flash else False } try: @@ -192,7 +198,8 @@ class AsyncNimbusSMS: "text": message, "entityid": self.__entity_id, "templateid": template_id, - "type": message_type + "type": message_type, + "flash": flash } )