diff --git a/README.md b/README.md index 6c036cd..5b809fd 100755 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ The token that the [BotFather](https://core.telegram.org/bots#botfather) gives y **TELEGRAM_WEBHOOK** (optional) -You can specify a [webhook](https://core.telegram.org/bots/api#setwebhook) URL which the adapter will register with Telegram. This URL will receive updates from Telegram. The adapter automatically registers an endpoint with Hubot at http://your-hobot-host/hubot/telegram/receive. +You can specify a [webhook](https://core.telegram.org/bots/api#setwebhook) URL. The adapter will register TELEGRAM_WEBHOOK/TELEGRAM_TOKEN with Telegram and listen there. **TELEGRAM_INTERVAL** (optional) @@ -68,4 +68,4 @@ robot.respond(/(.*)/i, function (res) { ## Contributors * Luke Simone - [https://github.com/lukefx](https://github.com/lukefx) -* Chris Brand - [https://github.com/arcturial](https://github.com/arcturial) \ No newline at end of file +* Chris Brand - [https://github.com/arcturial](https://github.com/arcturial) diff --git a/src/telegram.coffee b/src/telegram.coffee index 265883e..398cfc4 100755 --- a/src/telegram.coffee +++ b/src/telegram.coffee @@ -217,11 +217,14 @@ class Telegram extends Adapter if @webhook - @api.invoke 'setWebHook', { url: @webhook }, (err, result) -> + endpoint = @webhook + '/' + @token + @robot.logger.debug 'Listening on ' + endpoint + + @api.invoke 'setWebHook', { url: endpoint }, (err, result) -> if (err) self.emit 'error', err - @robot.router.post "/hubot/telegram/receive", (req, res) => + @robot.router.post "/" + @token, (req, res) => if req.body.message self.handleUpdate req.body