Q:

Python fbchat Library Questions

I have two main questions about the fbchat library. The first is hypothetical, and the second is code/function based.
My first question is can fbchat return when a user is online? When I use this code:
 persons = client.getUsers(name)
 for person in persons:
    person_info = client.getUserInfo(person.uid)
    if person_info['is_friend'] == True:
        print person_info

I get something like this (replaced all info with generic things out of respect for privacy):
{u'alternateName': u'', u'name': u'Name', u'firstName': u'Name', u'gender': 2, u'thumbSrc': u'url', u'uri': u'url', u'searchTokens': [u'Name', u'Name'], u'dir': None, u'is_friend': True, u'numbers/letters': number, u'mThumbSrcSmall': None, u'is_nonfriend_messenger_contact': False, u'type': u'friend', u'id': u'number', u'mThumbSrcLarge': None, u'vanity': u'messenger_id'}

I was wondering if one of these was a measure to see if the person was online, or how to do so.
Second question is about the reading of messages. Using this code, I get an error (pasted bellow the code).
def check_message():
    client = login()
    friend = "Name"

    last_messages = client.getThreadInfo(client.getUsers(friend)[0].uid, 0)
    last_messages.reverse()

    for message in last_messages:
        print(message.body)

This is the error:
Traceback (most recent call last):
  File "C:/Users/lukec/PycharmProjects/Sysgen_AI/test.py", line 32, in <module>
    check_message()
  File "C:/Users/lukec/PycharmProjects/Sysgen_AI/test.py", line 30, in check_message
    print(message.body)
AttributeError: Message instance has no attribute 'body'

But the fb chat pypi page says that message.body does exist...
Also, when I remove the .body at the end, I get this output instead:
<fbchat.models.Message instance at value>
<fbchat.models.Message instance at value>
<fbchat.models.Message instance at value>
<fbchat.models.Message instance at value>
<fbchat.models.Message instance at value>
<fbchat.models.Message instance at value>
<fbchat.models.Message instance at value>
<fbchat.models.Message instance at value>
<fbchat.models.Message instance at value>
<fbchat.models.Message instance at value>
<fbchat.models.Message instance at value>

Any idea why? I am building a personal bot/AI that covers a variety of tasks.
Edit: Using @fsociety's suggestion, dir(message) returns the following:
['__doc__', '__init__', '__module__', u'action_type', u'attachments', u'author', u'author_email', u'body', u'commerce_message_type', u'customizations', u'ephemeral_ttl_mode', u'folder', u'forward_count', u'forward_message_ids', u'has_attachment', u'is_filtered_content', u'is_filtered_content_account', u'is_filtered_content_bh', u'is_filtered_content_invalid_app', u'is_filtered_content_quasar', u'is_forward', u'is_sponsored', u'is_spoof_warning', u'is_unread', u'message_id', u'message_source', u'meta_ranges', u'montage_reply_data', u'offline_threading_id', u'other_user_fbid', u'platform_xmd', u'profile_ranges', u'ranges', u'raw_attachments', u'reactions', u'skip_bump_thread', u'source', u'source_tags', u'subject', u'tags', u'thread_fbid', u'thread_id', u'threading_id', u'timestamp', u'timestamp_absolute', u'timestamp_datetime', u'timestamp_relative', u'timestamp_time_passed']

As you can see "body" comes up. I'm now more confused on why the error occurs. Also, why is the first one (person_info) different from this one (message)? I'd expect it to be a dict as well (so a key can be called).
Edit 2: Using the following, I get an error:
def check_message():
    client = login()
    friend = "Name"

    last_messages = client.getThreadInfo(client.getUsers(friend)[0].uid, 0)
    last_messages.reverse()

    for message in last_messages:
        print(message['body'])

The error is:
 File "C:/Users/lukec/PycharmProjects/Sysgen_AI/test.py", line 33, in <module>
    check_message()
 File "C:/Users/lukec/PycharmProjects/Sysgen_AI/test.py", line 31, in check_message
    print(message['body'])
 AttributeError: Message instance has no attribute '__getitem__'

Thoughts?
Edit 3: Printing other attributes of the message works, just not the body... for example, I can
print message.timestamp_datetime

and get:
October 10, 2016 7:16 pm

as output. Not sure if the message.body issue is me or the library then. Any workarounds you can think of?

A:

Figured it out:
When a friend finally joins Messenger, Facebook sends an alert to you stating so. fbchat sees this as a message and tries to cache and parse it, but gets tripped up on it not having a body.
Using this:
for Message in last_messages:
    message_time = Message.timestamp_datetime
        try:
            message_body = Message.body
            print message_time
            print message_body
        except:
            pass

It gets passed the issue of the first message not having a body and can go on to print subsequent messages.
Thanks so much for your help @SancaKembang. I wouldn't have figured it out if you'd never linked this. It got me to look into the library files themselves and see why the error was arising versus just looking at my code.

