Coder Social home page Coder Social logo

facebook-messenger-bot-tutorial's Introduction

facebook-messenger-bot-tutorial

教你建立自己的 facebook-messenger-bot 使用 Python Django 📝

facebook-messenger-bot-tutorial use Python Django

執行畫面

alt tag

alt tag

alt tag

alt tag

alt tag

alt tag

alt tag

alt tag

alt tag

希望這個 阿肥bot 能幫助大家,程式碼基本上就是很簡單的爬蟲。

如果需要其他的功能,可以給小弟一點建議,我會盡量完成他。

教學

請先到 facebook-developers 這裡登入自己原本的 facebook 帳號,然後點選 右上角 選 新增應用程式

alt tag

填寫一些設定,填完後,按 建立應用程式編號

alt tag

接下來,先選擇左方的 新增產品 , 再選擇 Messenger

alt tag

再設定裡面的 權杖產生 裡,必須先申請一個 粉絲專頁,如果沒有請先申請,直接點選即可申請

alt tag

alt tag

新增完粉絲專業之後,可以看到自己的 token (權杖),記得選自己的粉絲專頁

alt tag

接著把 fb_setting.py 裡面的內容改成自己的,如下

ACCESS_TOKEN 就是你的 token (權杖)

VERIFY_TOKEN 可以隨便打

ACCESS_TOKEN = "xxxx"

VERIFY_TOKEN = "1234567890"

接著先將程式執行起來。

如何使用 ngrok

請去下載 ngrok ,免安裝版本,解壓縮即可使用,

是什麼呢? 簡單說,就是讓自己的內網 ( 也就是 localhost) 可以讓別人看的到,

好處是什麼呢? 讓我們可以在本機測試自己的 bot

那該如何使用

首先,請用 cmd 切換到 ngrok.exe 路徑底下,然後輸入

ngrok http 8000

alt tag

如果路徑正確,你應該會看到下圖

紅色框框就是你要用的網址,記得選 https

alt tag

接著找到 Webhooks ,然後按編輯 (如果你找不到,第一次他會在 Messenger 裡面)

alt tag

網址 以及你的 VERIFY_TOKEN 貼到下方 ,

網址: https://5d3e3183.ngrok.io/fb_mybot/callback/ (請貼你自己的)

VERIFY_TOKEN : 1234567890 (自己任意設定即可)

alt tag

如果你設定完全正確,你的 cmd 應該會顯示 200 OK

alt tag

如果沒顯示 200 OK,請再查查看哪裡錯誤了,

檢查是不是忘記訂閱 Webhooks 了

alt tag

佈署

目前沒有部屬,因為 FACEBOOK 審核我覺得有點麻煩,所以就暫時沒有佈署了。

其他補充

  • 目前僅有本機測試 ( 未部屬 heroku 以及 通過 FB 的審核),直接密粉絲團 bot 不會有反應。

  • 只要有使用到網址,請記得一定都要用 https

  • ngrok 如果重開,網址會改變,需要重新設定你的 Webhooks。 ( 設定完之後,有時候會慢一點才會有反應)

執行環境

  • Python 3.4.3 + Django

Reference

Donation

文章都是我自己研究內化後原創,如果有幫助到您,也想鼓勵我的話,歡迎請我喝一杯咖啡:laughing:

alt tag

贊助者付款

License

MIT license

facebook-messenger-bot-tutorial's People

Contributors

twtrubiks avatar

Watchers

 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.