We respond to user’s message through Graph API using the stored user id and message id.Ī detailed breakdown of the above code is available of this website.We respond to the Facebook’s request and store the id of the user and the message which was sent to our page.Facebook sends a request to our server whenever a user messages our page on Facebook.So basically a Facebook bot works like this: We will be modifying the file according to our needs. """Send the message text to recipient with id recipient. Yield event, "I can't echo this"ĭef send_message(token, recipient, text): Yield event, event.encode('unicode_escape') If "message" in event and "text" in event: """Generate tuples of (sender_id, message_text) from the Print "Incoming from %s: %s" % (sender, message) Return 'Error, wrong validation methods=)įor sender, message in messaging_events(payload): If ('hub.verify_token', '') = 'my_voice_is_my_password_verify_me': # by the Facebook App that will be created. # This needs to be filled with the Page Access Token that will be provided The below code is taken from Konstantinos Tsaprailis’s website. Follow the on-screen install instructions and come back once it has been installed. On the next page give your application a unique name.įrom the next page click on “Heroku CLI” and download the latest Heroku CLI for your operating system. Go to this dashboard url and create a new application. Now we need to setup the base for our Heroku app. So now that your app is created you need to save the ‘client_id' and ‘client_secret' in a safe place. For production apps it is better to put in something related to your project so that if you start making a lot of requests and reddit starts to notice it they can check the about page of you app and act in a more informed manner. The about and redirect url will not be used hence it is ok to leave them blank. Click on “create another app” and follow the on-screen instructions. In the above image you can already see the “motivation” app which I have created. Next you need to create a Reddit application on this link. Firstly, make sure that you have an account on all three of these services. We will be using Facebook, Heroku and Reddit. Getting things ready Creating a Reddit app Reddit – As a data source because it get’s new posts every minuteġ.Heroku – For hosting our code online for free.Flask framework for coding up the backend as it is lightweight and allows us to focus on the logic instead of the folder structure.In this post I will teach you most of the stuff you need to know in order to get your bot off the ground.įirst of all some screenshots of the final product: It was the first time I had delved into bot creation. It was a Facebook messenger bot which servers you fresh memes, motivational posts, jokes and shower thoughts. However, on the past weekend I managed to get a hold of my laptop and crank out something useful. Hi guys! I haven’t been programming a lot lately because of exams. Source Making a Reddit + Facebook Messenger Bot April 12, 2017
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |