Skip to content

BaseBotRequestHandler Class

Innocent Bystander edited this page Aug 17, 2015 · 2 revisions

This is the method documentation for BaseBotRequestHandler class, the base class used by sinks. In bot version 2.7 and above, it is superseded by AsyncRequestHandler - a drop-in replacement class which is more flexible and has better response times.

Methods

do_POST

def do_POST()
  • processes incoming POST request
  • pseudo-code:
    • breaks request into:
      • path - the URL component following the domain name
      • query_string - the URL component following the path
      • content - string payload in the body of the request (expected to be JSON)
    • calls BaseBotRequestHandler.send_data

process_request

def process_request( path, 
                     query_string, 
                     content )
  • if overridden, decorate with @asyncio.coroutine
  • pseudo-code:
    • receives path, query_string and content
      • path is split by "/" and the first element of the resulting list is assumed to be a target conversation_id (to send a message)
      • query_string is ignored
      • content is assumed to be valid JSON and parsed into dict payload:
        • payload["echo"] will be the html-formatted message to send
        • payload["image"] can consist of two subkeys:
          • payload["image"]["base64encoded"] is a base64-encoded string of an image to send, it is decoded into a io.BytesIO object image_data
          • payload["image"]["filename"] is the filename of the image and assigned to image_filename
            • if no filename is provided, will attempt to determine image type and assign the correct extension with a name based on the current date and time
    • calls send_data(conversation_id, html, image_data=None, image_filename=None)

send_data

def send_data( conversation_id, 
               html, 
               image_data=None, 
               image_filename=None )
  • sends a message containing html-formatted text and/or an image to a conversation
  • if overridden, decorate with @asyncio.coroutine
  • pseudo-code:
    • if image_data is provided, the image will be automatically uploaded for use by the bot
      • image_filename is optional but recommended - since process_request determines the type of image uploaded. if the method was overridden and no image_filename provided, it will fallback to <datetime>.jpg and output a warning
    • html is parsed by the available parser in the bot - as of 2.4 the parser supports simplified Markdown and HTML
    • sends the message to the appropriate conversation

# ## ###

Clone this wiki locally