项目作者: risan

项目描述 :
😽 Facebook Messenger bot that will reply your chat with a cute cat GIF
高级语言: JavaScript
项目地址: git://github.com/risan/cute-cat-bot.git
创建时间: 2017-01-19T21:25:45Z
项目社区:https://github.com/risan/cute-cat-bot

开源协议:MIT License

下载


Cute Cat Bot

Code Style: Prettier
License

A Facebook Messenger bot that will reply your chat with a cute cat GIF. Try it here!

Cute Cat Bot

Requirements

The following items are required to run this application sample:

Installation

This project is available on Glitch: glitch.com/~three-conifer.

1. Clone this repository

First, clone this repository to your local computer:

  1. git clone git@github.com:risan/cute-cat-bot.git

2. Install the dependencies

Next, CD to the project directory and install all of the dependencies:

  1. # Go to the project directory
  2. cd cute-cat-bot
  3. # Install all of the dependencies
  4. npm install

3. Setting up environment variables

The next step is to configure your environment variables to run the application.

Copy the .env.example file to .env:

  1. cp .env.example .env

Open up the .env file then set each directives properly.

  1. // .env
  2. PORT=3000
  3. FB_API_VERSION=2.11
  4. FB_APP_SECRET=YOUR_APP_SECRET
  5. FB_VERIFY_TOKEN=YOUR_MESSENGER_VERIFY_TOKEN
  6. FB_PAGE_ACCESS_TOKEN=YOUR_FACE_BOOK_PAGE_ACCESS
  7. GIPHY_API_KEY=YOUR_GIPHY_API_KEY

Heads up to the Facebook App page and select your application. Make sure that Messenger is added to your product. If not, click on the Add Product button an select the Messenger.

  • FB_APP_SECRET: You’ll find your app secret withi the Dashboard page of your application
  • FB_VERIFY_TOKEN: Fill this with some random string, you’ll use this to verify the webhook
  • FB_PAGE_ACCESS_TOKEN: Go to the Messenger > Settings menu. Find the Token Generation section and select your Facebook page that you want to use.
  • GIPHY_API_KEY: Heads up here to create a new app and get your Giphy API key

4. Run the application 🎉

Run the application by typing the following command:

  1. npm run start

Then expose the running application with Ngrok by running:

  1. ngrok http PORT_NUMBER

Replace the PORT_NUMBER with the one that you set within the .env file. You’ll get the following output from Ngrok:

  1. Forwarding http://foobar123.ngrok.io -> localhost:3000
  2. Forwarding https://foobar123.ngrok.io -> localhost:3000

Head back to the Facebook App page and select your application. Go to the Messenger > Settings menu. Find the Webhook section and click on the Setup Webhook button. Check the messages subscription field and set:

  1. Callback URL: https://foobar123.ngrok.io/webhook
  2. Verify Token: FB_VERIFY_TOKEN from your .env file

Click the Verify and Save button. And once it’s verified, you’re good to go to test the chat bot 🎉

If you want to change your webhook URL later, head back to the Facebook App and select your application. You’ll find a Webhook menu under the products now. Open it and click on the Edit Subscription button. You can reconfigure the URL and the verification token.

License

MIT © Risan Bagja Pradana