Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

listen to messages (fb bot) #101

Closed
milo123milo opened this issue Feb 6, 2017 · 22 comments
Closed

listen to messages (fb bot) #101

milo123milo opened this issue Feb 6, 2017 · 22 comments

Comments

@milo123milo
Copy link

Hi guys!
Is it possible to make a fb bot alike with this code? I need something that will listen constanly to messages and on type of message send it to client. Something like jarvis fb bot, but without using heroku etc.

Thanks!

@madsmtm
Copy link
Member

madsmtm commented Feb 6, 2017

It's very much possible, but it probably requires quite a lot of python knowledge, and a lot of time. Try looking at the example echobot

@milo123milo
Copy link
Author

yeah i dont need something special. i just need to my pyton command recive message when i send it.
that echobot dont work for me, it give me error. Something about json? @madsmtm

@madsmtm
Copy link
Member

madsmtm commented Feb 6, 2017

If there is something specific that's not working for you, please provide more information (Logs, debug output, error messages, and so on)

@milo123milo
Copy link
Author

This is error which i get.

`Logging in...
login successful

Traceback (most recent call last):
File "C:\Users\Korisnik\Desktop\fbtest.py", line 19, in
bot.listen()
File "C:\Python27\lib\site-packages\fbchat\client.py", line 544, in listen
sticky, pool = self._getSticky()
File "C:\Python27\lib\site-packages\fbchat\client.py", line 468, in getSticky
j = get_json(r.text)
File "C:\Python27\lib\site-packages\fbchat\utils.py", line 18, in get_json
return json.loads(re.sub(r"^[^{]*", '', text, 1))
File "C:\Python27\lib\json_init
.py", line 339, in loads
return _default_decoder.decode(s)
File "C:\Python27\lib\json\decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python27\lib\json\decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded`

@madsmtm
Copy link
Member

madsmtm commented Feb 6, 2017

Are you sure you are using the latest version? Try running pip install fbchat --upgrade

@milo123milo
Copy link
Author

i'm getting lxlm error?

@milo123milo
Copy link
Author

lxml**

@milo123milo
Copy link
Author

and i have lxml instaled.

@milo123milo
Copy link
Author

can it be because i have 2 pytons installed 3.0 and 2.7?

@madsmtm
Copy link
Member

madsmtm commented Feb 6, 2017

Most people have both python 2 and python 3 installed. To specifically select a version, use python2, python3, pip2 and pip3 respectively

@milo123milo
Copy link
Author

image

still :( ?

@milo123milo
Copy link
Author

i make it out. so is there way to make message be equal to something?

@madsmtm
Copy link
Member

madsmtm commented Feb 6, 2017

You can just use self.send(author_id, '<your message here>')

@milo123milo
Copy link
Author

yeah, but i need to make 'message' equal to smothenig. So i can make a fb bot. I'm thinking something about this:

if recived_message == "hi" send message (hi!)

I just give you rought explame of my need. Hope u get it :)

Thanks!

@madsmtm
Copy link
Member

madsmtm commented Feb 6, 2017

I understand, and applaude, your will to make something big quickly, but explaining how the basics of python works is a bit too much for this thread. Try looking up some tutorials online, it shouldn't be too hard, since you already seem to understand some of the basics of programming. Good luck :)

@milo123milo
Copy link
Author

Thanks. :)

@milo123milo
Copy link
Author

I see u have better knowelage than me :) can u help me with my problem? I just need to access variable from class so i can use it in whole script. ? :)

@milo123milo
Copy link
Author

Rest, i think, i will make out :)

@afonsocarlos
Copy link
Contributor

Can't you store variable in self like self.your_variable = 'what you want to store'? That is, supposing you're inside a class

@milo123milo
Copy link
Author

How can i make this to work?

`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 str(author_id) != str(self.uid):
        self.send(author_id,message)

bot = EchoBot("ID", "PASS")
bot.listen()

if message == "hi" :
#do something
`

@milo123milo
Copy link
Author

But the if function on the end must stay out of class. Is that even possible? xD

@Dainius14
Copy link
Contributor

@milo123milo look at my project https://github.com/Dainius14/fb-chat-bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants