Request¶
-
class
glados.request.GladosRequest(route_type, route=None, slack_verify=None, bot_name=None, json=None, data=None, **kwargs)[source]¶ Bases:
objectGLaDOS Request Object. This holds all the data required to process the request.
Parameters: - route_type (
RouteType) – what type of route is this - route (
Optional[str]) – what is the route to be called - slack_verify (
Optional[SlackVerification]) – slack data used for verifying the request came from Slack - bot_name (
Optional[str]) – The name of the bot to send the request to. This is used for select RouteTypes - json (
Union[str,dict,None]) – the json paylod of the request - data (
Optional[dict]) – data to send with the request. This should be from a database - kwargs –
Examples
>>> request = GladosRequest(RouteType.SendMessage, "send_mock", json={"message":"my message"}) >>> print(request.json.message) my message >>> try: ... print(request.json.other_param) ... except AttributeError: ... print("ERROR") ERROR
-
add_interaction_to_datastore(interaction)[source]¶ Add an interaction to the datastore and return the updated interaction.
Notes
The interaction_id can be retrieved by doing interaction.interaction_id
Parameters: interaction ( DataStoreInteraction) – the interaction to be addedReturn type: Optional[DataStoreInteraction]
-
data_blob¶ Returns the raw dict of the data object
Return type: dict
-
gen_new_interaction(*, followup_action=None, followup_ts=None, ttl=None, data=None, auto_link=True, auto_set=True)[source]¶ Generate a new interaction object and set it as new_interaction.
Parameters: - followup_action –
- followup_ts –
- ttl –
- data –
- auto_link (
bool) – set this request to auto-link using the return payload. The return payload must be the response from sending a slack message. - auto_set (
bool) – set this new interaction object as the request new_interaction
Return type:
-
interaction¶ Returns the interaction for the request
Return type: Optional[DataStoreInteraction]
-
interaction_id¶ Returns the interaction_id of request.interaction
Return type: Optional[str]
-
link_interaction_to_message(interaction_id, channel, message_ts)[source]¶ Link interaction to message
Parameters: - interaction_id (
str) – interaction ID to link - channel (
str) – channel to be linked to - message_ts (
datetime) – ts to be linked to
Return type: NoReturn- interaction_id (
-
link_interaction_to_message_response(interaction_id, message_response)[source]¶ Link interaction to message response
Parameters: - interaction_id (
str) – interaction ID to be linked - message_response (
dict) – JSON payload response from sending message on slack.
Return type: NoReturn- interaction_id (
-
route¶ the actual route
If the route automatically prefixed the route with the bot name, it will return the route with the prefix
Return type: str
-
set_datastore(datastore)[source]¶ Set the Datastore and session for the request.
Parameters: datastore ( DataStore) – Datastore to use. This datastore will be used to create the session.Return type: NoReturn
- route_type (
-
class
glados.request.SlackVerification(data, timestamp=None, signature=None)[source]¶ Bases:
objectAn object to hold slack verification data
Parameters: - data (
str) – raw request body. This is used to verify the message is from slack. - timestamp (
Optional[str]) – The X-Slack-Request-Timestamp from the headers of the request. This is used to verify the message is from slack. - signature (
Optional[str]) – The X-Slack-Signature from the headers of the request. This is used to verify the message is from slack.
-
json¶ Returns the dict of the SlackVerification
Return type: dict
- data (