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 thisroute (
Optional
[str
]) – what is the route to be calledslack_verify (
Optional
[SlackVerification
]) – slack data used for verifying the request came from Slackbot_name (
Optional
[str
]) – The name of the bot to send the request to. This is used for select RouteTypesjson (
Union
[str
,dict
,None
]) – the json paylod of the requestdata (
Optional
[dict
]) – data to send with the request. This should be from a databasekwargs –
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
]
-
property
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
-
property
interaction
¶ Returns the interaction for the request
- Return type
Optional
[DataStoreInteraction
]
-
property
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 linkchannel (
str
) – channel to be linked tomessage_ts (
datetime
) – ts to be linked to
- Return type
NoReturn
-
link_interaction_to_message_response
(interaction_id, message_response)[source]¶ Link interaction to message response
- Parameters
interaction_id (
str
) – interaction ID to be linkedmessage_response (
dict
) – JSON payload response from sending message on slack.
- Return type
NoReturn
-
property
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
-
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.
-
property
json
¶ Returns the dict of the SlackVerification
- Return type
dict