fbchat icon indicating copy to clipboard operation
fbchat copied to clipboard

fetchThreadList error due to unknown thread type: MARKETPLACE

Open c-manano opened this issue 5 years ago • 5 comments

Description of the problem

fetchThreadList fails when a Marketplace thread type is returned (e.g. when you click on "Message Seller" in a "Buy and Sell" group).

Code to reproduce

# Example code
from fbchat import Client
client = Client("[REDACTED_USERNAME]", "a_password_with_%")
client.fetchThreadList()

Traceback

Traceback (most recent call last):
  File "/.../fbchat/_client.py", line 1161, in fetchThreadList
    graphql_to_thread(node) for node in j["viewer"]["message_threads"]["nodes"]
  File "/.../fbchat/_client.py", line 1161, in <listcomp>
    graphql_to_thread(node) for node in j["viewer"]["message_threads"]["nodes"]
  File "/.../fbchat/_graphql.py", line 493, in graphql_to_thread
    thread.get("thread_type"), thread
fbchat._exception.FBchatException: Unknown thread type: MARKETPLACE, with data: {...}

Environment information

  • Python version 3.7.0
  • fbchat version 1.6.4

I added a elif clause to graphql_to_thread to avoid an interruption and still retrieving the others GROUP/ONE_TO_ONE threads

c-manano avatar Mar 20 '19 15:03 c-manano

Attaching the thread data JSON (in Python Dict) here for your reference.

All redacted information are replaced with text enclosed by <>.

Data JSON
{
  "thread_key": { "thread_fbid": "<THREAD_ID_INT>", "other_user_id": None },
  "name": "<BUYER_FIRST_NAME> · <ITEM_NAME>",
  "last_message": {
    "nodes": [
      {
        "snippet": "Yes",
        "message_sender": { "messaging_actor": { "id": "<SELLER_USER_ID>" } },
        "timestamp_precise": "1561698007567",
        "commerce_message_type": None,
        "extensible_attachment": None,
        "sticker": None,
        "blob_attachments": []
      }
    ]
  },
  "unread_count": 0,
  "messages_count": 4,
  "image": {
    "uri": "https://scontent-lga3-1.xx.fbcdn.net/v/t1.6435-9/65204446_2323057997740116_7556936468447363072_n.jpg?_nc_cat=107&_nc_oc=AQm_NfLGwHYCryMpEEf-XDmSRxY9q-rEwSLpWEEDCd_XndgWZyc7SATD4MxsDK9S-3k&_nc_ht=scontent-lga3-1.xx&oh=780f85a4d9c582503bda029f99a3ef61&oe=5DC538D4"
  },
  "updated_time_precise": "1561698007567",
  "mute_until": None,
  "is_pin_protected": False,
  "is_pinned": False,
  "is_viewer_subscribed": True,
  "thread_queue_enabled": True,
  "folder": "INBOX",
  "has_viewer_archived": False,
  "is_page_follow_up": False,
  "cannot_reply_reason": None,
  "ephemeral_ttl_mode": 0,
  "customization_info": None,
  "thread_theme": None,
  "thread_admins": [],
  "approval_mode": 0,
  "joinable_mode": { "mode": "0", "link": "" },
  "group_approval_queue": { "nodes": [] },
  "thread_queue_metadata": { "approval_requests": { "nodes": [] } },
  "event_reminders": { "nodes": [] },
  "montage_thread": None,
  "last_read_receipt": { "nodes": [{ "timestamp_precise": "1561698007567" }] },
  "related_page_thread": None,
  "rtc_call_data": {
    "call_state": "NO_ONGOING_CALL",
    "server_info_data": "",
    "initiator": None
  },
  "marketplace_thread_data": {
    "for_sale_item": {
      "id": "<ITEM_ID_INT>",
      "story_id": "<STORY_ID_BASE64>",
      "group_commerce_item_title": "<ITEM_NAME>",
      "formatted_price": { "text": "$85" },
      "location": {
        "reverse_geocode": { "city": "<CITY_NAME>", "state": "<STATE_CODE>" }
      },
      "is_sold": False,
      "primary_photo": {
        "image": {
          "uri": "https://scontent-lga3-1.xx.fbcdn.net/v/t1.0-9/65318151_2323056564406926_4420521933230047232_n.jpg?_nc_cat=105&_nc_oc=AQmOFbY8cen93JdW7YDA76UabKUii6qaLRxIjYsainhug_MCILx2MVDh4DPtqmOSKCA&_nc_ht=scontent-lga3-1.xx&oh=a1f59e43804762567bc676119a46b571&oe=5D7C91CD"
        }
      },
      "url": "https://www.facebook.com/marketplace/item/<ITEM_ID_INT>/"
    },
    "buyer": { "id": "<BUYER_USER_ID>" },
    "seller": { "id": "<SELLER_USER_ID>" }
  },
  "associated_object": None,
  "privacy_mode": 1,
  "reactions_mute_mode": "REACTIONS_NOT_MUTED",
  "mentions_mute_mode": "MENTIONS_NOT_MUTED",
  "customization_enabled": True,
  "thread_type": "MARKETPLACE",
  "participant_add_mode_as_string": "ADD",
  "is_canonical_neo_user": False,
  "participants_event_status": [],
  "page_comm_item": None,
  "admin_model_status_string": "not_supported",
  "groups_sync_status_string": "UNSET",
  "groups_sync_metadata": None,
  "saved_messages": [],
  "description": None,
  "joinable_link": None,
  "all_participants": {
    "nodes": [
      { "messaging_actor": { "id": "<BUYER_USER_ID>", "__typename": "User" } },
      { "messaging_actor": { "id": "<SELLER_USER_ID>", "__typename": "User" } }
    ]
  }
}

blueset avatar Jul 04 '19 01:07 blueset

+1

ajlyakhov avatar Jul 12 '19 14:07 ajlyakhov

+1

wpcreation2018 avatar Jul 13 '19 07:07 wpcreation2018

+1

unclepeach avatar Aug 02 '19 02:08 unclepeach

To make it easier for everyone since the code is moved since the issue was reported: here's the version of code that sill has graphql_to_thread function.

At the moment it fails at the end of fetchThreadList method. Ironically, if it wasn't inlined, it'd be easier to monkey patch the method and make it defensive :)

At the moment, I've used somewhat horrible (but I think, working) monkey patching that filteres out all MARKETPLACE threads from API responses.

Sadly, I don't have any marketplace conversations, otherwise I'd happily contribute a proper fix for that issue to fbchat!

karlicoss avatar Jan 20 '20 19:01 karlicoss