       (cb) => @changeNick cb,
       (cb) => @syncContacts cb
     ], (err, results) =>
+      if err isnt null
+        @robot.logger.error 'Error during data sync: '+JSON.stringify err
       @robot.logger.debug 'Everything synced, ready to go!'
       @emit 'synced', @
 

    @on 'pollcomplete', (resp) =>
      @robot.logger.debug 'Poll complete'
      @handleStreamEvents resp
      @robot.logger.debug 'Sending new poll request'
      @poll()

  post: (path, body = {}, callback) ->
    request = new WebRequest(@robot.logger, @ticket, @token_id)
    request.post path, body, (error, response, metaData) =>

      if response.ticket?

    textMessage = new TextMessage author, text
    @emit 'gotMessage', textMessage

  # Send a new long poll request to the Fleep API
  # The request will wait ~90 seconds
  # If new information is available, the server will respond immediately
  poll: =>
    @robot.logger.debug 'Starting long poll request'
    data =
      wait: true,
      event_horizon: @getLastEventHorizon()
      poll_flags: ['skip_hidden']

    @post 'account/poll', data, (err, resp) =>
      @emit 'pollcomplete', resp

  # Send a new message to Fleep
  send: (envelope, message) =>
    @robot.logger.debug 'Sending new message to conversation ' + envelope.room

    @post "message/send/#{envelope.room}", {message: message}, (err, resp) ->
      if err isnt null
        @robot.logger.error 'Unable to send a message: '+JSON.stringify err


  # Send a private message to a user
  reply: (envelope, message) ->
    @robot.logger.debug 'Sending private message to user ' + envelope.user.id

    @post 'conversation/create', {
      topic: null, # Topic is currently empty, the default is the bot's name
      emails:envelope.user.email,
      message: message
    }, (err, resp) ->
      if err isnt null
        @robot.logger.error 'Unable to send a 1:1 message: '+JSON.stringify err

  # Get a hash of known conversations
  getKnownConversations: =>
    @robot.brain.get('conversations') ? {}

  # Mark a Fleep message as 'seen' by the bot
  markRead: (conversation_id, message_nr) =>

    # Save the last message number into an internal tracker
