Request

class glados.request.GladosRequest(route_type, route=None, slack_verify=None, bot_name=None, json=None, data=None, **kwargs)[source]

Bases: object

GLaDOS 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 added
Return type:Optional[DataStoreInteraction]
close_session()[source]

Close session for request

Return type:NoReturn
data

Returns the data object of the request

Return type:PyJSON
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:

DataStoreInteraction

has_interaction()[source]

Check if request has interaction.

Return type:bool
has_new_interaction()[source]

check if request has a new interaction object.

Return type:bool
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

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

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

rollback_session()[source]

Rollback the session.

Return type:NoReturn
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
set_interaction_from_datastore()[source]

Get the interaction object from the datastore.

Return type:NoReturn
set_session(session)[source]

Set the session for this request.

Parameters:session (Session) – session to use for this request.
Raises:ConnectionError – If the session is not active raise a ConnectionError
Return type:NoReturn
class glados.request.SlackVerification(data, timestamp=None, signature=None)[source]

Bases: object

An 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