-
Notifications
You must be signed in to change notification settings - Fork 2
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.
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
- breaks request into:
def process_request( path,
query_string,
content )
- if overridden, decorate with
@asyncio.coroutine
- pseudo-code:
- receives
path
,query_string
andcontent
-
path
is split by "/" and the first element of the resulting list is assumed to be a targetconversation_id
(to send a message) -
query_string
is ignored -
content
is assumed to be valid JSON and parsed intodict 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 aio.BytesIO
objectimage_data
-
payload["image"]["filename"]
is the filename of the image and assigned toimage_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)
- receives
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 - sinceprocess_request
determines the type of image uploaded. if the method was overridden and noimage_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
- if
Plugin List | Developer Reference: [ Intro | Plugins | Sinks | In-built Functionality | [Configuration] (Configuration) ]