diff --git a/README.md b/README.md index a2b0b10..6def584 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,19 @@ The `WootConnector` requires the following environment variables to be set: Run your Cel.ai assistant, then a new Chatwoot bot called "Bot Name" will be created in your Chatwoot instance. Assign the bot to any Inbox you want to use it with. +## Implemented Features + +| | RECEIVE | SEND | +|---------------------|:-------:|:-----:| +| **Text** | ✅ | ✅ | +| **Image** | ✅ | ❌ | +| **Audio** | ✅ | ❌ | +| **Files** | ✅ | ❌ | +| **Custom Attributes** | ❌ | ❌ | +| **Video** | ❌ | ❌ | +| **Location** | ✅ | ❌ | +| **Buttons** | - | ❌ | +| **Templates** | - | ❌ | ## Roadmap diff --git a/celai_chatwoot/connector/model/woot_attachment.py b/celai_chatwoot/connector/model/woot_attachment.py index 81b6e9f..262ab30 100644 --- a/celai_chatwoot/connector/model/woot_attachment.py +++ b/celai_chatwoot/connector/model/woot_attachment.py @@ -3,6 +3,10 @@ LocationAttachment,\ MessageAttachmentType +class WootLocationAttachment(LocationAttachment): + def __init__(self, **kwargs): + super().__init__(**kwargs) + class WootAttachment(FileAttachment): @@ -59,18 +63,14 @@ async def load_from_message(cls, message: dict) -> list: # Sample message with image attachment from Chatwoot - # { "attachments": [ - # { - # "id": 11529, - # "message_id": 436117, - # "file_type": "image", - # "account_id": 8, - # "extension": null, - # "data_url": "https://chatwoot.celai.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBbG91IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--1a8d1d96c0630370245a7f741b16990c82c4e3bb/ale1.jpg", - # "thumb_url": "https://chatwoot.celai.com/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBbG91IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--1a8d1d96c0630370245a7f741b16990c82c4e3bb/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lJYW5CbkJqb0dSVlE2RTNKbGMybDZaVjkwYjE5bWFXeHNXd2RwQWZvdyIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--27ede0471899a6e40b40ba7e4525adebc0ea198f/ale1.jpg", - # "file_size": 160813 - # } - # ],} + # "id": 11529, + # "message_id": 436117, + # "file_type": "image", + # "account_id": 8, + # "extension": null, + # "data_url": "https://chatwoot.celai.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBbG91IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--1a8d1d96c0630370245a7f741b16990c82c4e3bb/ale1.jpg", + # "thumb_url": "https://chatwoot.celai.com/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBbG91IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--1a8d1d96c0630370245a7f741b16990c82c4e3bb/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lJYW5CbkJqb0dSVlE2RTNKbGMybDZaVjkwYjE5bWFXeHNXd2RwQWZvdyIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--27ede0471899a6e40b40ba7e4525adebc0ea198f/ale1.jpg", + # "file_size": 160813 @classmethod async def load_image_from_message(cls, attach: dict): @@ -86,41 +86,64 @@ async def load_image_from_message(cls, attach: dict): # Sample audio message from Chatwoot - # { - # ... - # "attachments": [ - # { - # "id": 207, - # "message_id": 2467, - # "file_type": "audio", - # "account_id": 4, - # "extension": null, - # "data_url": "https://chatwoot.com/rails/asd.oga" - # "thumb_url": "", - # "file_size": 7989 - # } - # ] - # } + # "id": 207, + # "message_id": 2467, + # "file_type": "audio", + # "account_id": 4, + # "extension": null, + # "data_url": "https://chatwoot.com/rails/asd.oga" + # "thumb_url": "", + # "file_size": 7989 @classmethod async def load_audio_from_message(cls, attach: dict): + filename = attach["data_url"].split("/")[-1] return WootAttachment( - title="Audio", + title=filename, description="Audio attachment", - mimeType="audio", + mimeType=mimetypes.guess_type(attach["data_url"])[0], metadata=attach, file_url=attach["data_url"], type=MessageAttachmentType.AUDIO ) - + # Sample location message from Chatwoot + # "id": 15184, + # "message_id": 595490, + # "file_type": "location", + # "account_id": 8, + # "coordinates_lat": -34.574992, + # "coordinates_long": -58.502302, + # "fallback_title": null, + # "data_url": null @classmethod async def load_location_from_message(cls, attach: dict): - raise NotImplementedError("Location attachment not implemented") + return WootLocationAttachment( + latitude=attach["coordinates_lat"], + longitude=attach["coordinates_long"], + metadata=attach, + description="Location attachment") + # "id": 15185, + # "message_id": 595520, + # "file_type": "file", + # "account_id": 8, + # "extension": null, + # "data_url": "https://chatwoot.celai.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBcGs4IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--67392c158ee9d2e382c576d70eaba10ca95c786e/file_2.pdf", + # "thumb_url": "", + # "file_size": 18810 @classmethod async def load_file_from_message(cls, attach: dict): - raise NotImplementedError("File attachment not implemented") + filename = attach["data_url"].split("/")[-1] + return WootAttachment( + title=filename, + description="File attachment", + mimeType=mimetypes.guess_type(attach["data_url"])[0], + metadata=attach, + file_url=attach["data_url"], + type=MessageAttachmentType.DOCUMENT + ) + @classmethod async def load_video_from_message(cls, attach: dict): diff --git a/celai_chatwoot/connector/woo_connector.py b/celai_chatwoot/connector/woo_connector.py index f3a614e..8d965c8 100644 --- a/celai_chatwoot/connector/woo_connector.py +++ b/celai_chatwoot/connector/woo_connector.py @@ -72,7 +72,7 @@ async def __process_message(self, payload: dict): try: log.debug("Received Chatwoot request") - log.debug(payload) + # log.debug(payload) if payload.get("message_type", "outgoing") == "outgoing": log.debug("Ignoring outgoing message") @@ -80,6 +80,10 @@ async def __process_message(self, payload: dict): msg = await WootMessage.load_from_message(payload, connector=self) + has_attachments = msg.attachments is not None and len(msg.attachments) > 0 + if has_attachments: + log.debug(f"Received message with attachments: {msg.attachments}") + assert isinstance(msg, WootMessage), "msg must be an instance of WootMessage" diff --git a/pyproject.toml b/pyproject.toml index 97f96ee..9052013 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "celai-chatwoot" -version = "0.1.2" +version = "0.1.3" description = "" authors = ["Alex Martin "] readme = "README.md" diff --git a/tests/data/incoming_audio_msg_tg.json b/tests/data/incoming_audio_msg_tg.json new file mode 100644 index 0000000..a408505 --- /dev/null +++ b/tests/data/incoming_audio_msg_tg.json @@ -0,0 +1,152 @@ +{ + "account": { + "id": 8, + "name": "Demos" + }, + "additional_attributes": {}, + "content_attributes": {}, + "content_type": "text", + "content": null, + "conversation": { + "additional_attributes": { + "chat_id": 1320141990 + }, + "can_reply": true, + "channel": "Channel::Telegram", + "contact_inbox": { + "id": 6981, + "contact_id": 6849, + "inbox_id": 216, + "source_id": "1320141990", + "created_at": "2024-09-21T04:41:45.211Z", + "updated_at": "2024-09-21T04:41:45.211Z", + "hmac_verified": false, + "pubsub_token": "d4EAQrREKUcMtTJCcmcTiEn5" + }, + "id": 35, + "inbox_id": 216, + "messages": [ + { + "id": 595489, + "content": null, + "account_id": 8, + "inbox_id": 216, + "conversation_id": 35, + "message_type": 0, + "created_at": 1726894319, + "updated_at": "2024-09-21T04:51:59.084Z", + "private": false, + "status": "sent", + "source_id": "8", + "content_type": "text", + "content_attributes": {}, + "sender_type": "Contact", + "sender_id": 6849, + "external_source_ids": {}, + "additional_attributes": {}, + "processed_message_content": null, + "conversation": { + "assignee_id": null, + "unread_count": 1, + "last_activity_at": 1726894319 + }, + "attachments": [ + { + "id": 15183, + "message_id": 595489, + "file_type": "audio", + "account_id": 8, + "extension": null, + "data_url": "https://chatwoot.celai.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBcGc4IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--ced19bdedff4a7da3eee55e466fe5bc1506d0832/file_1.oga", + "thumb_url": "", + "file_size": 4062 + } + ], + "sender": { + "additional_attributes": { + "username": "cowbe1985", + "language_code": "en" + }, + "custom_attributes": {}, + "email": null, + "id": 6849, + "identifier": null, + "name": "AMPer ", + "phone_number": null, + "thumbnail": "", + "type": "contact" + } + } + ], + "labels": [], + "meta": { + "sender": { + "additional_attributes": { + "username": "cowbe1985", + "language_code": "en" + }, + "custom_attributes": {}, + "email": null, + "id": 6849, + "identifier": null, + "name": "AMPer ", + "phone_number": null, + "thumbnail": "", + "type": "contact" + }, + "assignee": null, + "team": null, + "hmac_verified": false + }, + "status": "open", + "custom_attributes": {}, + "snoozed_until": null, + "unread_count": 1, + "first_reply_created_at": "2024-09-21T04:42:30.327Z", + "priority": null, + "agent_last_seen_at": 1726894291, + "contact_last_seen_at": 0, + "timestamp": 1726894319, + "created_at": 1726893705 + }, + "created_at": "2024-09-21T04:51:59.084Z", + "id": 595489, + "inbox": { + "id": 216, + "name": "Test Bot" + }, + "message_type": "incoming", + "private": false, + "sender": { + "account": { + "id": 8, + "name": "Demos" + }, + "additional_attributes": { + "username": "cowbe1985", + "language_code": "en" + }, + "avatar": "", + "custom_attributes": {}, + "email": null, + "id": 6849, + "identifier": null, + "name": "AMPer ", + "phone_number": null, + "thumbnail": "" + }, + "source_id": "8", + "attachments": [ + { + "id": 15183, + "message_id": 595489, + "file_type": "audio", + "account_id": 8, + "extension": null, + "data_url": "https://chatwoot.celai.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBcGc4IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--ced19bdedff4a7da3eee55e466fe5bc1506d0832/file_1.oga", + "thumb_url": "", + "file_size": 4062 + } + ], + "event": "message_created" +} \ No newline at end of file diff --git a/tests/data/incoming_file_msg_tg.json b/tests/data/incoming_file_msg_tg.json new file mode 100644 index 0000000..8077fcf --- /dev/null +++ b/tests/data/incoming_file_msg_tg.json @@ -0,0 +1,152 @@ +{ + "account": { + "id": 8, + "name": "Demos" + }, + "additional_attributes": {}, + "content_attributes": {}, + "content_type": "text", + "content": "sample pdf for testing", + "conversation": { + "additional_attributes": { + "chat_id": 1320141990 + }, + "can_reply": true, + "channel": "Channel::Telegram", + "contact_inbox": { + "id": 6981, + "contact_id": 6849, + "inbox_id": 216, + "source_id": "1320141990", + "created_at": "2024-09-21T04:41:45.211Z", + "updated_at": "2024-09-21T04:41:45.211Z", + "hmac_verified": false, + "pubsub_token": "d4EAQrREKUcMtTJCcmcTiEn5" + }, + "id": 35, + "inbox_id": 216, + "messages": [ + { + "id": 595520, + "content": "sample pdf for testing", + "account_id": 8, + "inbox_id": 216, + "conversation_id": 35, + "message_type": 0, + "created_at": 1726895312, + "updated_at": "2024-09-21T05:08:32.046Z", + "private": false, + "status": "sent", + "source_id": "10", + "content_type": "text", + "content_attributes": {}, + "sender_type": "Contact", + "sender_id": 6849, + "external_source_ids": {}, + "additional_attributes": {}, + "processed_message_content": "sample pdf for testing", + "conversation": { + "assignee_id": null, + "unread_count": 1, + "last_activity_at": 1726895312 + }, + "attachments": [ + { + "id": 15185, + "message_id": 595520, + "file_type": "file", + "account_id": 8, + "extension": null, + "data_url": "https://chatwoot.leapfinancial.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBcGs4IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--67392c158ee9d2e382c576d70eaba10ca95c786e/file_2.pdf", + "thumb_url": "", + "file_size": 18810 + } + ], + "sender": { + "additional_attributes": { + "username": "cowbe1985", + "language_code": "en" + }, + "custom_attributes": {}, + "email": null, + "id": 6849, + "identifier": null, + "name": "AMPer ", + "phone_number": null, + "thumbnail": "", + "type": "contact" + } + } + ], + "labels": [], + "meta": { + "sender": { + "additional_attributes": { + "username": "cowbe1985", + "language_code": "en" + }, + "custom_attributes": {}, + "email": null, + "id": 6849, + "identifier": null, + "name": "AMPer ", + "phone_number": null, + "thumbnail": "", + "type": "contact" + }, + "assignee": null, + "team": null, + "hmac_verified": false + }, + "status": "open", + "custom_attributes": {}, + "snoozed_until": null, + "unread_count": 1, + "first_reply_created_at": "2024-09-21T04:42:30.327Z", + "priority": null, + "agent_last_seen_at": 1726894903, + "contact_last_seen_at": 0, + "timestamp": 1726895312, + "created_at": 1726893705 + }, + "created_at": "2024-09-21T05:08:32.046Z", + "id": 595520, + "inbox": { + "id": 216, + "name": "Test Bot" + }, + "message_type": "incoming", + "private": false, + "sender": { + "account": { + "id": 8, + "name": "Demos" + }, + "additional_attributes": { + "username": "cowbe1985", + "language_code": "en" + }, + "avatar": "", + "custom_attributes": {}, + "email": null, + "id": 6849, + "identifier": null, + "name": "AMPer ", + "phone_number": null, + "thumbnail": "" + }, + "source_id": "10", + "attachments": [ + { + "id": 15185, + "message_id": 595520, + "file_type": "file", + "account_id": 8, + "extension": null, + "data_url": "https://chatwoot.celai.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBcGs4IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--67392c158ee9d2e382c576d70eaba10ca95c786e/file_2.pdf", + "thumb_url": "", + "file_size": 18810 + } + ], + "event": "message_created" +} \ No newline at end of file diff --git a/tests/data/incoming_location_tg.json b/tests/data/incoming_location_tg.json new file mode 100644 index 0000000..131bbd4 --- /dev/null +++ b/tests/data/incoming_location_tg.json @@ -0,0 +1,152 @@ +{ + "account": { + "id": 8, + "name": "Demos" + }, + "additional_attributes": {}, + "content_attributes": {}, + "content_type": "text", + "content": null, + "conversation": { + "additional_attributes": { + "chat_id": 1320141990 + }, + "can_reply": true, + "channel": "Channel::Telegram", + "contact_inbox": { + "id": 6981, + "contact_id": 6849, + "inbox_id": 216, + "source_id": "1320141990", + "created_at": "2024-09-21T04:41:45.211Z", + "updated_at": "2024-09-21T04:41:45.211Z", + "hmac_verified": false, + "pubsub_token": "d4EAQrREKUcMtTJCcmcTiEn5" + }, + "id": 35, + "inbox_id": 216, + "messages": [ + { + "id": 595490, + "content": null, + "account_id": 8, + "inbox_id": 216, + "conversation_id": 35, + "message_type": 0, + "created_at": 1726894902, + "updated_at": "2024-09-21T05:01:42.712Z", + "private": false, + "status": "sent", + "source_id": "9", + "content_type": "text", + "content_attributes": {}, + "sender_type": "Contact", + "sender_id": 6849, + "external_source_ids": {}, + "additional_attributes": {}, + "processed_message_content": null, + "conversation": { + "assignee_id": null, + "unread_count": 1, + "last_activity_at": 1726894902 + }, + "attachments": [ + { + "id": 15184, + "message_id": 595490, + "file_type": "location", + "account_id": 8, + "coordinates_lat": -34.574992, + "coordinates_long": -58.502302, + "fallback_title": null, + "data_url": null + } + ], + "sender": { + "additional_attributes": { + "username": "cowbe1985", + "language_code": "en" + }, + "custom_attributes": {}, + "email": null, + "id": 6849, + "identifier": null, + "name": "AMPer ", + "phone_number": null, + "thumbnail": "", + "type": "contact" + } + } + ], + "labels": [], + "meta": { + "sender": { + "additional_attributes": { + "username": "cowbe1985", + "language_code": "en" + }, + "custom_attributes": {}, + "email": null, + "id": 6849, + "identifier": null, + "name": "AMPer ", + "phone_number": null, + "thumbnail": "", + "type": "contact" + }, + "assignee": null, + "team": null, + "hmac_verified": false + }, + "status": "open", + "custom_attributes": {}, + "snoozed_until": null, + "unread_count": 1, + "first_reply_created_at": "2024-09-21T04:42:30.327Z", + "priority": null, + "agent_last_seen_at": 1726894319, + "contact_last_seen_at": 0, + "timestamp": 1726894902, + "created_at": 1726893705 + }, + "created_at": "2024-09-21T05:01:42.712Z", + "id": 595490, + "inbox": { + "id": 216, + "name": "Test Bot" + }, + "message_type": "incoming", + "private": false, + "sender": { + "account": { + "id": 8, + "name": "Demos" + }, + "additional_attributes": { + "username": "cowbe1985", + "language_code": "en" + }, + "avatar": "", + "custom_attributes": {}, + "email": null, + "id": 6849, + "identifier": null, + "name": "AMPer ", + "phone_number": null, + "thumbnail": "" + }, + "source_id": "9", + "attachments": [ + { + "id": 15184, + "message_id": 595490, + "file_type": "location", + "account_id": 8, + "coordinates_lat": -34.574992, + "coordinates_long": -58.502302, + "fallback_title": null, + "data_url": null + } + ], + "event": "message_created" +} \ No newline at end of file diff --git a/tests/messages_test.py b/tests/messages_test.py index 3bd4d07..cd2d469 100644 --- a/tests/messages_test.py +++ b/tests/messages_test.py @@ -2,23 +2,41 @@ import pytest from cel.gateway.model.conversation_lead import ConversationLead from celai_chatwoot.connector.model import WootLead -from celai_chatwoot.connector.model.woot_attachment import WootAttachment +from celai_chatwoot.connector.model.woot_attachment import WootAttachment, WootLocationAttachment from celai_chatwoot.connector.model.woot_message import WootMessage + + @pytest.fixture def msg() -> str: - with open('./tests/data/incoming_text_msg_from_web.json') as f: message = json.load(f) return message @pytest.fixture def msg_img() -> str: - with open('./tests/data/incoming_img_msg_from_web.json') as f: message = json.load(f) return message + +@pytest.fixture +def msg_audio_from_tg() -> str: + with open('./tests/data/incoming_audio_msg_tg.json') as f: + message = json.load(f) + return message +@pytest.fixture +def msg_location_from_tg() -> str: + with open('./tests/data/incoming_location_tg.json') as f: + message = json.load(f) + return message + +@pytest.fixture +def msg_file_from_tg() -> str: + with open('./tests/data/incoming_file_msg_tg.json') as f: + message = json.load(f) + return message + @pytest.mark.asyncio async def test_lead_parsing(msg): @@ -80,3 +98,80 @@ async def test_message_with_img_parsing(msg_img): assert attach.file_url == 'https://chatwoot.celai.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBbG91IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--1a8d1d96c0630370245a7f741b16990c82c4e3bb/ale1.jpg' assert attach.thumb_url == 'https://chatwoot.celai.com/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBbG91IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--1a8d1d96c0630370245a7f741b16990c82c4e3bb/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lJYW5CbkJqb0dSVlE2RTNKbGMybDZaVjkwYjE5bWFXeHNXd2RwQWZvdyIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--27ede0471899a6e40b40ba7e4525adebc0ea198f/ale1.jpg' + +@pytest.mark.asyncio +async def test_message_with_audio_parsing(msg_audio_from_tg): + wootmsg = await WootMessage.load_from_message(msg_audio_from_tg) + + assert isinstance(wootmsg, WootMessage) + assert wootmsg.text == None or wootmsg.text == '' + assert wootmsg.date == 1726894319 + + # Audio attachment + # "id": 15183, + # "message_id": 595489, + # "file_type": "audio", + # "account_id": 8, + # "extension": null, + # "data_url": "https://chatwoot.celai.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBcGc4IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--ced19bdedff4a7da3eee55e466fe5bc1506d0832/file_1.oga", + # "thumb_url": "", + # "file_size": 4062 + + assert len(wootmsg.attachments) == 1 + attach = wootmsg.attachments[0] + assert isinstance(attach, WootAttachment) + assert attach.title == "file_1.oga" + assert attach.mimeType == 'audio/ogg' + assert attach.file_url == 'https://chatwoot.celai.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBcGc4IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--ced19bdedff4a7da3eee55e466fe5bc1506d0832/file_1.oga' + + + +@pytest.mark.asyncio +async def test_message_with_location_parsing(msg_location_from_tg): + wootmsg = await WootMessage.load_from_message(msg_location_from_tg) + + assert isinstance(wootmsg, WootMessage) + assert wootmsg.text == None or wootmsg.text == '' + assert wootmsg.date == 1726894902 + + # "id": 15184, + # "message_id": 595490, + # "file_type": "location", + # "account_id": 8, + # "coordinates_lat": -34.574992, + # "coordinates_long": -58.502302, + # "fallback_title": null, + # "data_url": null + + assert len(wootmsg.attachments) == 1 + attach = wootmsg.attachments[0] + assert isinstance(attach, WootLocationAttachment) + assert attach.type == 'location' + assert attach.latitude == -34.574992 + assert attach.longitude == -58.502302 + + +@pytest.mark.asyncio +async def test_message_file_pdf(msg_file_from_tg): + wootmsg = await WootMessage.load_from_message(msg_file_from_tg) + + assert isinstance(wootmsg, WootMessage) + assert wootmsg.text == 'sample pdf for testing' + assert wootmsg.date == 1726895312 + + # "id": 15185, + # "message_id": 595520, + # "file_type": "file", + # "account_id": 8, + # "extension": null, + # "data_url": "https://chatwoot.celai.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBcGs4IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--67392c158ee9d2e382c576d70eaba10ca95c786e/file_2.pdf", + # "thumb_url": "", + # "file_size": 18810 + + assert len(wootmsg.attachments) == 1 + attach = wootmsg.attachments[0] + assert isinstance(attach, WootAttachment) + + assert attach.title == "file_2.pdf" + assert attach.mimeType == 'application/pdf' + assert attach.file_url == 'https://chatwoot.celai.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBcGs4IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--67392c158ee9d2e382c576d70eaba10ca95c786e/file_2.pdf' \ No newline at end of file