Skip to content

Commit 58e6fb9

Browse files
committed
change config to object
1 parent b41d523 commit 58e6fb9

File tree

3 files changed

+307
-46
lines changed

3 files changed

+307
-46
lines changed

src/bot.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ export default class LineBot extends EventEmitter {
2222
return _sourceTypes
2323
}
2424

25-
constructor (secret, token, options = {}) {
25+
constructor ({secret, token, options = {}}) {
2626
super()
2727
this.secret = secret
2828
this.token = token
2929
this.options = options
3030
this._Webhook = new Webhook({
3131
secret,
3232
token,
33-
webhookOpts: options.webhook,
33+
options,
3434
onEvents: this.processEvents.bind(this),
35-
onWebhook: (port) => {
36-
this.emit('webhook', port)
35+
onWebhook: (webhook) => {
36+
this.emit('webhook', webhook)
3737
},
3838
onTunnel: (args) => {
3939
this.emit('tunnel', args)

src/webhook.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const DEFAULT_ENDPOINT = '/'
1010
const DEFAULT_TUNNEL = false
1111

1212
class Webhook {
13-
constructor ({secret, token, webhookOpts = {}, onEvents, onWebhook, onTunnel}) {
13+
constructor ({secret, token, options = {}, onEvents, onWebhook, onTunnel}) {
1414
this.secret = secret
1515
this.token = token
1616
this.onEvents = onEvents
@@ -21,10 +21,10 @@ class Webhook {
2121
this._createTunnel = this._createTunnel.bind(this)
2222

2323
const app = express()
24-
const APP_PORT = webhookOpts.port || DEFAULT_PORT
25-
const APP_ENDPOINT = webhookOpts.endpoint || DEFAULT_ENDPOINT
26-
const APP_TUNNEL = webhookOpts.tunnel || webhookOpts.ngrok || DEFAULT_TUNNEL
27-
const IS_VERIFY_SIGNATURE = webhookOpts.verifySignature || false
24+
const APP_PORT = options.port || DEFAULT_PORT
25+
const APP_ENDPOINT = options.endpoint || DEFAULT_ENDPOINT
26+
const APP_TUNNEL = options.tunnel || options.ngrok || DEFAULT_TUNNEL
27+
const IS_VERIFY_SIGNATURE = options.verifySignature || false
2828

2929
app.use(morgan('dev'))
3030
if (IS_VERIFY_SIGNATURE) {
@@ -44,7 +44,7 @@ class Webhook {
4444
this._webserver = app
4545
this._webserver.listen(APP_PORT, (err) => {
4646
if (!err) {
47-
onWebhook(APP_PORT)
47+
onWebhook({port: APP_PORT, endpoint: APP_ENDPOINT})
4848
if (APP_TUNNEL) {
4949
this._createTunnel(APP_PORT).then(onTunnel).catch(onTunnel)
5050
}

0 commit comments

Comments
 (0)