-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example: add custom-server-express-typescript/ (#736)
- Loading branch information
1 parent
4404437
commit ea26d89
Showing
7 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
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,15 @@ | ||
MESSENGER_PAGE_ID= | ||
MESSENGER_ACCESS_TOKEN= | ||
MESSENGER_APP_ID= | ||
MESSENGER_APP_SECRET= | ||
MESSENGER_VERIFY_TOKEN= | ||
|
||
LINE_ACCESS_TOKEN= | ||
LINE_CHANNEL_SECRET= | ||
|
||
TELEGRAM_ACCESS_TOKEN= | ||
|
||
SLACK_ACCESS_TOKEN= | ||
SLACK_VERIFICATION_TOKEN= | ||
|
||
VIBER_ACCESS_TOKEN= |
38 changes: 38 additions & 0 deletions
38
examples/custom-server-express-typescript/bottender.config.js
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,38 @@ | ||
module.exports = { | ||
channels: { | ||
messenger: { | ||
enabled: true, | ||
path: '/webhooks/messenger', | ||
pageId: process.env.MESSENGER_PAGE_ID, | ||
accessToken: process.env.MESSENGER_ACCESS_TOKEN, | ||
appId: process.env.MESSENGER_APP_ID, | ||
appSecret: process.env.MESSENGER_APP_SECRET, | ||
verifyToken: process.env.MESSENGER_VERIFY_TOKEN, | ||
}, | ||
line: { | ||
enabled: true, | ||
path: '/webhooks/line', | ||
accessToken: process.env.LINE_ACCESS_TOKEN, | ||
channelSecret: process.env.LINE_CHANNEL_SECRET, | ||
}, | ||
telegram: { | ||
enabled: true, | ||
path: '/webhooks/telegram', | ||
accessToken: process.env.TELEGRAM_ACCESS_TOKEN, | ||
}, | ||
slack: { | ||
enabled: true, | ||
path: '/webhooks/slack', | ||
accessToken: process.env.SLACK_ACCESS_TOKEN, | ||
verificationToken: process.env.SLACK_VERIFICATION_TOKEN, | ||
}, | ||
viber: { | ||
enabled: true, | ||
path: '/webhooks/viber', | ||
accessToken: process.env.VIBER_ACCESS_TOKEN, | ||
sender: { | ||
name: 'xxxx', | ||
}, | ||
}, | ||
}, | ||
}; |
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 @@ | ||
module.exports = require('./dist').default; |
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,18 @@ | ||
{ | ||
"scripts": { | ||
"build": "tsc", | ||
"dev": "nodemon --exec ts-node src/server.ts", | ||
"start": "cross-env NODE_ENV=production node dist/server.js" | ||
}, | ||
"dependencies": { | ||
"body-parser": "^1.19.0", | ||
"bottender": "latest", | ||
"cross-env": "^6.0.3", | ||
"express": "^4.17.1" | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^2.0.1", | ||
"ts-node": "^8.8.2", | ||
"typescript": "^3.8.3" | ||
} | ||
} |
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,18 @@ | ||
import { | ||
LineContext, | ||
MessengerContext, | ||
SlackContext, | ||
TelegramContext, | ||
ViberContext, | ||
} from 'bottender'; | ||
|
||
export default async function App( | ||
context: | ||
| MessengerContext | ||
| LineContext | ||
| SlackContext | ||
| TelegramContext | ||
| ViberContext | ||
): Promise<void> { | ||
await context.sendText('Hello World'); | ||
} |
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,36 @@ | ||
import bodyParser from 'body-parser'; | ||
import express from 'express'; | ||
import { bottender } from 'bottender'; | ||
|
||
const app = bottender({ | ||
dev: process.env.NODE_ENV !== 'production', | ||
}); | ||
|
||
const port = Number(process.env.PORT) || 5000; | ||
|
||
const handle = app.getRequestHandler(); | ||
|
||
app.prepare().then(() => { | ||
const server = express(); | ||
|
||
server.use( | ||
bodyParser.json({ | ||
verify: (req, _, buf) => { | ||
(req as any).rawBody = buf.toString(); | ||
}, | ||
}) | ||
); | ||
|
||
server.get('/api', (req, res) => { | ||
res.json({ ok: true }); | ||
}); | ||
|
||
server.all('*', (req, res) => { | ||
return handle(req, res); | ||
}); | ||
|
||
server.listen(port, err => { | ||
if (err) throw err; | ||
console.log(`> Ready on http://localhost:${port}`); | ||
}); | ||
}); |
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,19 @@ | ||
{ | ||
"include": ["src/**/*"], | ||
"exclude": ["**/__tests__", "**/*.{spec,test}.ts"], | ||
"compilerOptions": { | ||
"target": "es2016", | ||
"lib": ["es2017", "es2018", "es2019", "esnext.asynciterable"], | ||
"module": "commonjs", | ||
"skipLibCheck": true, | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"rootDir": "./src", | ||
"outDir": "./dist", | ||
"types": ["node"] | ||
} | ||
} |