def message_actions(api: Client, action_type: str = 'send') -> None:
    """
    The last events of each chat of the current user
    will be shown or a message will be sent to a user chosen by the current user
    
    Arguments:
        api(client): client object of Instagram
        action_type (str) : Can be send or show

    """
    print_write_chatbot("IMPORTANT!!\n",
                        color='red',
                        attrs_color=['bold', 'blink', 'underline'])
    print_write_chatbot(
        "Thanks to Mark Zuckerberg, we can only show the latest events from each chat"
        ".\nWhether it is a like to a comment, share a profile / reel / publication / a message\n",
        color='red',
        attrs_color=['bold', 'underline'])

    try:
        if action_type != 'send':
            last_messages = api.direct_v2_inbox()['inbox']
            show_last_messages(last_messages, api.authenticated_user_id)
        else:
            send_message(api)

    except Exception as error:
        print(f"There was an error:{error}")
Beispiel #2
0
    except ClientLoginError as e:
        print('ClientLoginError {0!s}'.format(e))
        exit(9)
    except ClientError as e:
        print('ClientError {0!s} (Code: {1:d}, Response: {2!s})'.format(e.msg, e.code, e.error_response))
        exit(9)
    except Exception as e:
        print('Unexpected Exception: {0!s}'.format(e))
        exit(99)

    # Show when login expires
    cookie_expiry = api.cookie_jar.expires_earliest
    print('Cookie Expiry: {0!s}'.format(datetime.datetime.fromtimestamp(cookie_expiry).strftime('%Y-%m-%dT%H:%M:%SZ')))

    # Call the api
    results = api.direct_v2_inbox()
    unseen_count = results["inbox"]["unseen_count"]

    message_threads = results["inbox"]["threads"]

    #results = api.get_v2_threads()

    margesha_thread = 340282366841710300949128170938113262944
    #results = api._call_api('direct_v2/threads/{0}'.format(margesha_thread))
    
    #with open("marg__full_personal_chat.txt", "w") as f:
    #    f.write(json.dumps(results, indent = 4))

    #----------------
    #personal_thread = results["thread"]
    #other_person_name = personal_thread["users"][0]["username"]