This repository has been archived on 2025-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
Files
fbchat/examples/interract.py
2020-01-09 13:18:14 +01:00

68 lines
2.2 KiB
Python

import fbchat
session = fbchat.Session.login("<email>", "<password>")
client = fbchat.Client(session)
thread = fbchat.User(session=session, id=session.user_id)
# thread = fbchat.User(session=session, id="0987654321")
# thread = fbchat.Group(session=session, id="1234567890")
# Will send a message to the thread
thread.send(fbchat.Message(text="<message>"))
# Will send the default `like` emoji
thread.send(fbchat.Message(emoji_size=fbchat.EmojiSize.LARGE))
# Will send the emoji `👍`
thread.send(fbchat.Message(text="👍", emoji_size=fbchat.EmojiSize.LARGE))
# Will send the sticker with ID `767334476626295`
thread.send(fbchat.Message(sticker=fbchat.Sticker("767334476626295")))
# Will send a message with a mention
thread.send(
fbchat.Message(
text="This is a @mention",
mentions=[fbchat.Mention(thread.id, offset=10, length=8)],
)
)
# Will send the image located at `<image path>`
thread.send_local_image(
"<image path>", message=fbchat.Message(text="This is a local image")
)
# Will download the image at the URL `<image url>`, and then send it
thread.send_remote_image(
"<image url>", message=fbchat.Message(text="This is a remote image")
)
# Only do these actions if the thread is a group
if isinstance(thread, fbchat.Group):
# Will remove the user with ID `<user id>` from the group
thread.remove_participant("<user id>")
# Will add the users with IDs `<1st user id>`, `<2nd user id>` and `<3th user id>` to the group
thread.add_participants(["<1st user id>", "<2nd user id>", "<3rd user id>"])
# Will change the title of the group to `<title>`
thread.change_title("<title>")
# Will change the nickname of the user `<user_id>` to `<new nickname>`
thread.set_nickname(fbchat.User(session=session, id="<user id>"), "<new nickname>")
# Will set the typing status of the thread
thread.start_typing()
# Will change the thread color to `MESSENGER_BLUE`
thread.set_color(fbchat.ThreadColor.MESSENGER_BLUE)
# Will change the thread emoji to `👍`
thread.set_emoji("👍")
# message = fbchat.Message(session=session, id="<message id>")
#
# # Will react to a message with a 😍 emoji
# message.react(fbchat.MessageReaction.LOVE)