     return @robot.logger.error "No services token provided to Hubot" unless @options.token
     return @robot.logger.error "v2 services token provided, please follow the upgrade instructions" unless (@options.token.substring(0, 5) in ['xoxb-', 'xoxp-'])
 
-    # Create our slack client object
+    # Create our slack client objects
     @client = new RtmClient @options.token, @options
+    @webClient = new WebClient @options.token, @options # fallback for formatted messages
 
     # Setup event handlers
     # TODO: Handle eventual events at (re-)connection time for unreads and provide a config for whether we want to process them

{Robot, Adapter, EnterMessage, LeaveMessage, TopicMessage} = require 'hubot'
{SlackTextMessage, SlackRawMessage, SlackBotMessage} = require './message'
{SlackRawListener, SlackBotListener} = require './listener'
{RtmClient, MemoryDataStore} = require '@slack/client'

class SlackBot extends Adapter
  @MAX_MESSAGE_LENGTH: 4000


            msg = msg.substring(breakIndex, msg.length)

        @sendFormatted(m, envelope.room) for m in submessages

  sendFormatted: (message, room) ->    
    # RTM doesn't support formatted Urls, so we'll use the web client instead
    if /<.+\|.+>/.test(message)
      @webClient.chat.postMessage(room, message)
    else
      @client.sendMessage(message, room)


  reply: (envelope, messages...) ->
    @robot.logger.debug "Sending reply"
