-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move original example to single-page folder * Add multi-page example
- Loading branch information
Showing
12 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
PAGE_1_PAGE_ID=XXX | ||
PAGE_1_ACCESS_TOKEN=XXX | ||
|
||
PAGE_2_PAGE_ID=XXX | ||
PAGE_2_ACCESS_TOKEN=XXX | ||
|
||
APP_SECRET=XXX | ||
VERIFY_TOKEN=XXX | ||
WEBHOOK_URL=XXX |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"scripts": { | ||
"dev": "nodemon --exec \"node -r dotenv/config\" index.js", | ||
"start": "node -r dotenv/config index.js" | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^1.11.0" | ||
}, | ||
"dependencies": { | ||
"bottender": "latest", | ||
"bottender-fb": "latest", | ||
"dotenv": "^4.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const { Bot } = require('bottender'); | ||
const { createServer } = require('bottender/koa'); | ||
const { FacebookConnector } = require('bottender-fb'); | ||
|
||
const PAGE_1_PAGE_ID = process.env.PAGE_1_PAGE_ID; | ||
const PAGE_1_ACCESS_TOKEN = process.env.PAGE_1_ACCESS_TOKEN; | ||
|
||
const PAGE_2_PAGE_ID = process.env.PAGE_2_PAGE_ID; | ||
const PAGE_2_ACCESS_TOKEN = process.env.PAGE_2_ACCESS_TOKEN; | ||
|
||
const APP_SECRET = process.env.APP_SECRET; | ||
const VERIFY_TOKEN = process.env.VERIFY_TOKEN; | ||
|
||
const mapPageToAccessToken = pageId => { | ||
switch (pageId) { | ||
case PAGE_1_PAGE_ID: | ||
return PAGE_1_ACCESS_TOKEN; | ||
case PAGE_2_PAGE_ID: | ||
default: | ||
return PAGE_2_ACCESS_TOKEN; | ||
} | ||
}; | ||
|
||
const bot = new Bot({ | ||
connector: new FacebookConnector({ | ||
appSecret: APP_SECRET, | ||
mapPageToAccessToken, | ||
}), | ||
}); | ||
|
||
bot.onEvent(async context => { | ||
if (context.event.isCommentAdd) { | ||
try { | ||
await context.sendPrivateReply('OK!'); | ||
await context.sendComment('Public reply!'); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
}); | ||
|
||
const server = createServer(bot, { verifyToken: VERIFY_TOKEN }); | ||
|
||
module.exports = server; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const server = require('./server'); | ||
|
||
server.listen(3000, () => { | ||
console.log(`Server is running on localhost:3000`); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters