       
 exports.use = (robot) ->
   new Telegram robot
-  
# {Robot, Adapter, TextMessage, EnterMessage, LeaveMessage, TopicMessage} = require 'hubot'
{Robot, Adapter, TextMessage, User} = require 'hubot'
request = require 'request'


      @emit 'error', new Error `'The environment variable \`\033[31mTELEGRAM_TOKEN\033[39m\` is required.'`
    
    if @webHook
      # Call `setWebHook` to dynamically set the URL
      @robot.router.post "/telegram/receive", (req, res) =>
        console.log req.body
        for msg in req.body.result
          @robot.logger.info "WebHook"
          @receiveMsg msg
    else
      setInterval ->
        url = "#{self.api_url}/getUpdates?offset=#{self.getLastUpdateId()}"
        self.robot.http(url).get() (err, res, body) ->
          self.emit 'error', new Error err if err
          updates = JSON.parse body
          for msg in updates.result
            self.receiveMsg msg
