Giter Club home page Giter Club logo

fbchat's Introduction

fbchat

Facebook Chat (Messenger) for Python. This project was inspired by facebook-chat-api.

No XMPP or API key is needed. Just use your ID and PASSWORD.

if you have the c compiler problems with install lxml module , try manual install lxml from this site. http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

Installation

Simple:

$ pip install fbchat

Example

import fbchat

client = fbchat.Client("YOUR_ID", "YOUR_PASSWORD")

Sending a Message

friends = client.getUsers("FRIEND'S NAME")  # return a list of names
friend = friends[0]
sent = client.send(friend.uid, "Your Message")
if sent:
    print("Message sent successfully!")
# IMAGES
client.sendLocalImage(friend.uid,message='<message text>',image='<path/to/image/file>') # send local image
imgurl = "http://i.imgur.com/LDQ2ITV.jpg"
client.sendRemoteImage(friend.uid,message='<message text>', image=imgurl) # send image from image url

Getting user info from user id

friend1 = client.getUsers('<friend name 1>')[0]
friend2 = client.getUsers('<friend name 2>')[0]
friend1_info = client.getUserInfo(friend1.uid) # returns dict with details
both_info = client.getUserInfo(friend1.uid,friend2.uid) # query both together, returns list of dicts
friend1_name = friend1_info['name'] 

Getting last messages sent

last_messages = client.getThreadInfo(friend.uid,0)
last_messages.reverse()  # messages come in reversed order

for message in last_messages:
    print(message.body)

Example Echobot

import fbchat
#subclass fbchat.Client and override required methods
class EchoBot(fbchat.Client): 

    def __init__(self,email, password, debug=True, user_agent=None):            
        fbchat.Client.__init__(self,email, password, debug, user_agent)

    def on_message(self, mid, author_id, author_name, message, metadata):
        self.markAsDelivered(author_id, mid) #mark delivered
        self.markAsRead(author_id) #mark read

        print("%s said: %s"%(author_id, message))

        #if you are not the author, echo
        if str(author_id) != str(self.uid):
            self.send(author_id,message)

bot = EchoBot("<email>", "<password>")
bot.listen()

Authors

Taehoon Kim / @carpedm20

fbchat's People

Contributors

carpedm20 avatar pidgeyl avatar thekindlyone avatar wannaphong avatar charliiee avatar wcia avatar hashirzahir avatar johnathonnow avatar tcyrus avatar marchon avatar stanleykylee avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.