glados package¶
-
class
glados.
Glados
(config_file=None, plugins_folder=None, bots_config_dir=None, plugins_config_dir=None)[source]¶ Bases:
object
Glados is the core of the GLaDOS package.
Parameters: - config_file (
Optional
[str
]) – path to config file - plugins_folder (
Optional
[str
]) – path to plugins folder - bots_config_dir (
Optional
[str
]) – path to bots config folder - plugins_config_dir (
Optional
[str
]) – path to plugin config folder.
Notes
If
config_file
is passed in and the file hasplugins_folder
,bots_config_dir
,plugins_config_dir
in it , then the other parameters are not required-
add_bot
(bot)[source]¶ Add a new bot to GLaDOS.
Parameters: bot ( GladosBot
) – the bot to be added to GLaDOSReturn type: NoReturn
-
add_plugin
(plugin)[source]¶ Add a plugin to GLaDOS
Parameters: plugin ( GladosPlugin
) – the plugin to be added to GLaDOSReturn type: NoReturn
-
import_plugins
(bot_name=None)[source]¶ Import all discovered plugins and add them to the plugin list.
Parameters: bot_name ( Optional
[str
]) – If set GLaDOS will only import the bot name that is provided here.Return type: NoReturn
-
read_config
(bot_name=None)[source]¶ Read the GLaDOS config file. If a bot name is provided it will only install that bot. Else it will install all bots.
Parameters: bot_name ( Optional
[str
]) – If provided, install only the bot with this name.Return type: NoReturn
-
request
(request)[source]¶ Send a request to GLaDOS. This returns whatever the plugin returns.
This function will also set the datastore session for the request, try to find the interaction in the datastore and fetch it. This info is available in the request.
Parameters: request ( GladosRequest
) – the request to be sent to GLaDOS
- config_file (
-
class
glados.
GladosBot
(token, name, signing_secret=None, **kwargs)[source]¶ Bases:
object
GLaDOS Bot represents all the required data and functions for a Slack bot.
Notes
All Slack Web API functions can be called from MyBot.client.*
Parameters: - name (
str
) – The name of the bot (URL Safe) - token (
Union
[str
,Dict
[str
,str
]]) – The bot token - signing_secret (
Union
[str
,Dict
[str
,str
],None
]) – The bot signing secret.
-
name
¶ The name of the bot (URL Safe)
Type: str
-
token
¶ The bot token
Type: str
-
client
¶ A Slack client generated for that bot
Type: WebClient
-
signing_secret
¶ The bots signing secret.
Type: str
-
delete_message
(channel, ts)[source]¶ Deletes a message that was sent by a bot
Parameters: - channel (
str
) – - ts (
str
) –
Return type: MockObject
- channel (
-
send_message
(channel, message)[source]¶ Send a message as the bot
Parameters: - channel (
str
) – channel to send the message to - message (
MockObject
) – message object to send
Return type: MockObject
- channel (
-
update_message
(channel, ts, message)[source]¶ Updates a message that was sent by the bot
Parameters: - channel (
str
) – - ts (
str
) – - message (
MockObject
) –
Return type: MockObject
- channel (
-
validate_slack_signature
(request)[source]¶ Parameters: request ( GladosRequest
) –
- name (
-
class
glados.
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 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.
RouteType
[source]¶ Bases:
enum.Enum
An enumeration.
-
Callback
= 3¶
-
Events
= 5¶
-
Interaction
= 6¶
-
Menu
= 7¶
-
Response
= 2¶
-
Slash
= 4¶
-
Webhook
= 1¶
-
-
class
glados.
EventRoutes
[source]¶ Bases:
enum.Enum
An enumeration.
-
app_home_opened
= 1¶
-
message
= 2¶
-
-
class
glados.
GladosPlugin
(config, bot, **kwargs)[source]¶ Bases:
object
Parent class for a GLaDOS Plugin
Parameters: - config (
PluginConfig
) – PluginConfig object for the plugin. - bot (
GladosBot
) – the GLaDOS bot that this plugin will use
-
add_route
(route_type, route, function)[source]¶ Add a new route to the plugin
Parameters: - route_type (
RouteType
) – what type of route this is this - route (
Union
[EventRoutes
,str
]) – what is the route to be added - function (
Callable
) – the function to be executed when this route runs
Return type: NoReturn
- route_type (
-
has_route
(route)[source]¶ See if route exists.
Parameters: route (route to check) – Returns: Return type: True if route exists else false
-
respond_to_url
(request, text, **kwargs)[source]¶ When you click on a link that was sent via slack it sends a callback, This is to handle that
Parameters: - request (
GladosRequest
) – - text (
str
) –
- request (
-
routes
¶ List all routes for the plugin.
Return type: List
[GladosRoute
]
-
send_request
(request, **kwargs)[source]¶ This is the function to be called when sending a request to a plugin.
This function is responsible for validating the slack signature if needed. It also returns and empty string if the function called returns None.
Parameters: - request (
GladosRequest
) – the request object to be sent - kwargs –
Return type: Any
- request (
- config (
-
class
glados.
GladosConfig
(config_file)[source]¶ Bases:
object
Parameters: config_file ( str
) –-
sections
¶ what sections are there in the config file
Returns: Return type: sorted list of sections in the yaml file
-
-
glados.
check_for_env_vars
(value)[source]¶ Check an input value to see if it is an env_var or enc_env_var and get the value.
Parameters: value ( Union
[str
,dict
]) – input to check.Returns: Returns the value of the var from either the passed in value, or the env var value. Return type: Any Raises: KeyError if the env var is not set for what youre tying to get.
Submodules¶
glados.bot module¶
-
class
glados.bot.
GladosBot
(token, name, signing_secret=None, **kwargs)[source]¶ Bases:
object
GLaDOS Bot represents all the required data and functions for a Slack bot.
Notes
All Slack Web API functions can be called from MyBot.client.*
Parameters: - name (
str
) – The name of the bot (URL Safe) - token (
Union
[str
,Dict
[str
,str
]]) – The bot token - signing_secret (
Union
[str
,Dict
[str
,str
],None
]) – The bot signing secret.
-
name
¶ The name of the bot (URL Safe)
Type: str
-
token
¶ The bot token
Type: str
-
client
¶ A Slack client generated for that bot
Type: WebClient
-
signing_secret
¶ The bots signing secret.
Type: str
-
delete_message
(channel, ts)[source]¶ Deletes a message that was sent by a bot
Parameters: - channel (
str
) – - ts (
str
) –
Return type: MockObject
- channel (
-
send_message
(channel, message)[source]¶ Send a message as the bot
Parameters: - channel (
str
) – channel to send the message to - message (
MockObject
) – message object to send
Return type: MockObject
- channel (
-
update_message
(channel, ts, message)[source]¶ Updates a message that was sent by the bot
Parameters: - channel (
str
) – - ts (
str
) – - message (
MockObject
) –
Return type: MockObject
- channel (
-
validate_slack_signature
(request)[source]¶ Parameters: request ( GladosRequest
) –
- name (
glados.configs module¶
glados.core module¶
-
class
glados.core.
Glados
(config_file=None, plugins_folder=None, bots_config_dir=None, plugins_config_dir=None)[source]¶ Bases:
object
Glados is the core of the GLaDOS package.
Parameters: - config_file (
Optional
[str
]) – path to config file - plugins_folder (
Optional
[str
]) – path to plugins folder - bots_config_dir (
Optional
[str
]) – path to bots config folder - plugins_config_dir (
Optional
[str
]) – path to plugin config folder.
Notes
If
config_file
is passed in and the file hasplugins_folder
,bots_config_dir
,plugins_config_dir
in it , then the other parameters are not required-
add_bot
(bot)[source]¶ Add a new bot to GLaDOS.
Parameters: bot ( GladosBot
) – the bot to be added to GLaDOSReturn type: NoReturn
-
add_plugin
(plugin)[source]¶ Add a plugin to GLaDOS
Parameters: plugin ( GladosPlugin
) – the plugin to be added to GLaDOSReturn type: NoReturn
-
import_plugins
(bot_name=None)[source]¶ Import all discovered plugins and add them to the plugin list.
Parameters: bot_name ( Optional
[str
]) – If set GLaDOS will only import the bot name that is provided here.Return type: NoReturn
-
read_config
(bot_name=None)[source]¶ Read the GLaDOS config file. If a bot name is provided it will only install that bot. Else it will install all bots.
Parameters: bot_name ( Optional
[str
]) – If provided, install only the bot with this name.Return type: NoReturn
-
request
(request)[source]¶ Send a request to GLaDOS. This returns whatever the plugin returns.
This function will also set the datastore session for the request, try to find the interaction in the datastore and fetch it. This info is available in the request.
Parameters: request ( GladosRequest
) – the request to be sent to GLaDOS
- config_file (
glados.datastore module¶
-
class
glados.datastore.
DataStore
(host, username, password, port=5432, database='glados')[source]¶ Bases:
object
DataStore is how GLaDOS stores async data.
Parameters: - host (
str
) – postgres host. - username (
str
) – postgres username. - password (
str
) – postgres password. - port (
int
) – postgres port. - database (
str
) – postgres database to use.
-
create_table
(tables=None, force=False)[source]¶ Create the table.
If you set force to True then it will drop the existing tables and then recreate them. ALL DATA WILL BE LOST
Parameters: - tables (
Optional
[List
[str
]]) – only take action on these tables. If None, then take action on all tables - force (
bool
) – drop existing tables and rebuild. (default: False)
Return type: NoReturn
- tables (
-
drop_table
(table='interactions', force=False)[source]¶ Drop the GLaDOS table so that it can be re-created.
Parameters: - table (
str
) – table name to use. - force (
bool
) – if True will fill force drop the table without checks.
Return type: NoReturn
- table (
-
find_by_id
(interaction_id, session)[source]¶ Find an interaction by interaction_id.
Parameters: - interaction_id (
str
) – interaction ID to find - session (
Session
) – session to be used
Return type: - interaction_id (
-
find_interaction_by_channel_ts
(channel, ts, session)[source]¶ Find the interaction in the datastore by channel and message ts.
Parameters: - channel (
str
) – channel of the interaction youre looking for - ts (
datetime
) – ts of the interaction you are looking for - session (
Session
) – session to be used
Raises: ReferenceError
– There were more than one interaction that matched the channel and message_tsReturn type: Optional
[DataStoreInteraction
]- channel (
-
insert_interaction
(interaction, session)[source]¶ Insert an interaction object into the database.
Parameters: - interaction (
DataStoreInteraction
) – The row to be inserted - session (
Session
) – session to be used
Return type: NoReturn
- interaction (
-
link_to_message
(interaction_id, channel, ts, session)[source]¶ Link to message by setting message ts and channel.
Parameters: - interaction_id (
str
) – interaction ID to link - channel (
str
) – channel to link interaction to - ts (
datetime
) – ts to link interaction to - session (
Session
) – session to be used
Return type: NoReturn
- interaction_id (
-
link_to_message_response
(interaction_id, message_response, session)[source]¶ Add info from the Slack message into the database for the interaction.
Parameters: - interaction_id (
str
) – The interaction ID that was returned on adding the message to the database. - message_response (
dict
) – The raw message response from slack. The channel and ts will be pulled from this. - session (
Session
) – session to be used
Return type: NoReturn
- interaction_id (
-
table_exists
(table='interactions')[source]¶ Check to see if the GLaDOS table is found in postgres.
Parameters: table ( str
) – table name to use.Return type: bool
- host (
-
class
glados.datastore.
DataStoreInteraction
(**kwargs)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base
DataStoreInteraction represents a row in the datastore. This is used to update data in the datastore.
-
interaction_id
¶ This is the primary key of the datastore. This is the ID of the entry in the datastore.
Type: str
-
ts
¶ This is the time the row was put into the database.
Type: datetime
-
bot
¶ This is the name of the bot it should use when completing followup actions.
Type: str
-
data
¶ Any extra data stored with the interaction. This is a JSON blob.
Type: dict
-
message_channel
¶ The channel that this interaction was sent to.
Type: str
-
message_ts
¶ The message timestamp when this interaction was sent.
Type: datetime
-
ttl
¶ How long this interaction should live for.
Type: int
-
followup_ts
¶ When should the follow up action happen.
Type: datetime
-
followup_action
¶ The action name to execute when following up. If None then no action will happen.
Type: str
-
cron_followup_action
¶ The action name to execute on a normal cron schedule like every 5 min. If None then no action will happen.
Type: str
-
followed_up
¶ This is the time when the action was followed up at. If it has not happened yet this value will be None.
Type: datetime
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
bot
-
cron_followup_action
-
data
-
followed_up
-
followup_action
-
followup_ts
-
interaction_id
-
message_channel
-
message_ts
-
ts
-
ttl
-
glados.errors module¶
-
exception
glados.errors.
GladosBotNotFoundError
[source]¶ Bases:
glados.errors.GladosError
Error raised when GladosBot is not found
-
exception
glados.errors.
GladosPathExistsError
[source]¶ Bases:
glados.errors.GladosError
Error raised when trying to add a path that already exists
-
exception
glados.errors.
GladosRouteNotFoundError
[source]¶ Bases:
glados.errors.GladosError
Error raised when the requested path is not found
glados.message_blocks module¶
-
class
glados.message_blocks.
ModalBuilder
[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
The ModalBuilder enables you to more easily construct the JSON required to create a modal in Slack.
Modals are a focused surface to collect data from users or display dynamic and interactive information.
To learn how modals are invoked, how to compose their contents, and how to enable and handle complex interactivity read this guide:
https://api.slack.com/block-kit/surfaces/modals
-
actions
(*, elements, block_id=None)[source]¶ A block that is used to hold interactive elements.
https://api.slack.com/reference/block-kit/blocks#actions
Parameters: - elements (
List
[MockObject
]) – Up to 5 InteractiveElement objects - buttons, date pickers, etc - block_id (
Optional
[str
]) – ID to be used for this block - autogenerated if left blank. Cannot exceed 255 characters.
- elements (
-
attributes
= {'_blocks', '_callback_id', '_clear_on_close', '_close', '_external_id', '_notify_on_close', '_private_metadata', '_submit', '_title'}¶
-
blocks_max_length
= 100¶
-
callback_id
(callback_id)[source]¶ An identifier to recognize interactions and submissions of this particular modal. Don’t use this to store sensitive information (use private_metadata instead).
Parameters: callback_id ( str
) – must not exceed 255 charactersReturn type: ModalBuilder
-
clear_on_close
(clear_on_close)[source]¶ When set to true, clicking on the close button will clear all views in a modal and close it.
Parameters: clear_on_close ( bool
) – Default is false.Return type: ModalBuilder
-
close
(close)[source]¶ Specify the text displayed in the close button at the bottom-right of the view.
Max length of 24 characters.
Parameters: close ( str
) – must not exceed 24 charactersReturn type: ModalBuilder
-
close_max_length
= 24¶
-
context
(*, elements, block_id=None)[source]¶ Displays message context, which can include both images and text.
https://api.slack.com/reference/block-kit/blocks#context
Parameters: - elements (
List
[MockObject
]) – Up to 10 ImageElements and TextObjects - block_id (
Optional
[str
]) – ID to be used for this block - autogenerated if left blank. Cannot exceed 255 characters.
- elements (
-
divider
(*, block_id=None)[source]¶ A content divider, like an <hr>, to split up different blocks inside of a message.
Parameters: block_id ( Optional
[str
]) – A string acting as a unique identifier for a block. You can use this block_id when you receive an interaction payload to identify the docs-src of the action. If not specified, one will be generated. Maximum length for this field is 255 characters. block_id should be unique for each message and each iteration of a message. If a message is updated, use a new block_id.
-
external_id
(external_id)[source]¶ A custom identifier that must be unique for all views on a per-team basis.
Parameters: external_id ( str
) – A unique identifier.Return type: ModalBuilder
-
image
(*, image_url, alt_text, title=None, block_id=None)[source]¶ A simple image block, designed to make those cat photos really pop.
https://api.slack.com/reference/block-kit/blocks#image
Parameters: - image_url (
str
) – Publicly hosted URL to be displayed. Cannot exceed 3000 characters. - alt_text (
str
) – Plain text summary of image. Cannot exceed 2000 characters. - title (
Optional
[str
]) – A title to be displayed above the image. Cannot exceed 2000 characters. - block_id (
Optional
[str
]) – ID to be used for this block - autogenerated if left blank. Cannot exceed 255 characters.
- image_url (
-
notify_on_close
(notify_on_close)[source]¶ Indicates whether Slack will send your request URL a view_closed event when a user clicks the close button.
Parameters: notify_on_close ( bool
) – Default is false.Return type: ModalBuilder
-
private_metadata
(private_metadata)[source]¶ An optional string that will be sent to your app in view_submission and block_actions events.
Parameters: private_metadata ( str
) – must not exceed 3000 charactersReturn type: ModalBuilder
-
section
(*, text=None, block_id=None, fields=None, accessory=None)[source]¶ A section is one of the most flexible blocks available. It can be used as a simple text block, in combination with text fields, or side-by-side with any of the available block elements.
https://api.slack.com/reference/block-kit/blocks#section
Parameters: - text (
Union
[str
,MockObject
,None
]) – The text for the block, in the form of string or a text object. Maximum length for the text in this field is 3000 characters. - block_id (
Optional
[str
]) – A string acting as a unique identifier for a block. You can use this block_id when you receive an interaction payload to identify the docs-src of the action. If not specified, one will be generated. Maximum length for this field is 255 characters. block_id should be unique for each message and each iteration of a message. If a message is updated, use a new block_id. - fields (
Optional
[List
[str
]]) – optional: a sequence of strings that will be rendered using MarkdownTextObjects. Any strings included with fields will be rendered in a compact format that allows for 2 columns of side-by-side text. Maximum number of items is 10. Maximum length for the text in each item is 2000 characters. - accessory (
Optional
[MockObject
]) – an optional BlockElement to attach to this SectionBlock as secondary content
Return type: - text (
-
submit
(submit)[source]¶ Specify the text displayed in the submit button at the bottom-right of the view.
Important Note: submit is required when an input block is within the blocks array.
Max length of 24 characters.
Parameters: submit ( str
) – must not exceed 24 charactersReturn type: ModalBuilder
-
submit_max_length
= 24¶
-
title
(title)[source]¶ Specify a title for this modal
Parameters: title ( str
) – must not exceed 24 charactersReturn type: ModalBuilder
-
title_max_length
= 24¶
-
glados.plugin module¶
-
class
glados.plugin.
GladosPlugin
(config, bot, **kwargs)[source]¶ Bases:
object
Parent class for a GLaDOS Plugin
Parameters: - config (
PluginConfig
) – PluginConfig object for the plugin. - bot (
GladosBot
) – the GLaDOS bot that this plugin will use
-
add_route
(route_type, route, function)[source]¶ Add a new route to the plugin
Parameters: - route_type (
RouteType
) – what type of route this is this - route (
Union
[EventRoutes
,str
]) – what is the route to be added - function (
Callable
) – the function to be executed when this route runs
Return type: NoReturn
- route_type (
-
has_route
(route)[source]¶ See if route exists.
Parameters: route (route to check) – Returns: Return type: True if route exists else false
-
respond_to_url
(request, text, **kwargs)[source]¶ When you click on a link that was sent via slack it sends a callback, This is to handle that
Parameters: - request (
GladosRequest
) – - text (
str
) –
- request (
-
routes
¶ List all routes for the plugin.
Return type: List
[GladosRoute
]
-
send_request
(request, **kwargs)[source]¶ This is the function to be called when sending a request to a plugin.
This function is responsible for validating the slack signature if needed. It also returns and empty string if the function called returns None.
Parameters: - request (
GladosRequest
) – the request object to be sent - kwargs –
Return type: Any
- request (
- config (
-
class
glados.plugin.
PluginConfig
(name, config_file, module=None, enabled=False, bot=None, **kwargs)[source]¶ Bases:
object
Plugin Config Object.
Parameters: - name (
str
) – Plugin Name - config_file (
str
) – Path to config file for plugin - module – plugin python module name
- enabled – enable this plugin
- bot – what bot does this plugin use
- kwargs –
-
to_dict
(user_config_only=True)[source]¶ Return config as dict
Parameters: user_config_only – if True only get get waht is in the config file and not the running config. Return type: dict
-
update
(config, use_base_module=True)[source]¶ Update a config object using the default values from the config object passed in.
Parameters: - config (PluginConfig) – the config object to use as the base. By default the module property will be set from the base config object only
- use_base_module (bool) – if set true use the value of module and package from the base config object only.
Return type: NoReturn
- name (
-
class
glados.plugin.
PluginImporter
(plugins_folder, plugins_config_folder)[source]¶ Bases:
object
Create the PluginImporter object.
Parameters: - plugins_folder (
str
) – plugin folder - plugins_config_folder (
str
) – plugin config folder
-
discover_plugins
()[source]¶ Discover all plugin config files in the plugins folder
Return type: NoReturn
- plugins_folder (
glados.request module¶
-
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 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:
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
- data (
glados.route_type module¶
glados.router module¶
-
class
glados.router.
GladosRoute
(route_type, route, function)[source]¶ Bases:
object
Represents a single route
Parameters: - route_type (
RouteType
) – - route (
str
) – - function (
Callable
) –
- route_type (
-
class
glados.router.
GladosRouter
(**kwargs)[source]¶ Bases:
object
-
add_route
(plugin, route)[source]¶ Add a route to the router
Parameters: - plugin – the plugin the route belongs to
- route (
GladosRoute
) – the route to be added
Raises: KeyError
– a route with the same type and same name already existsReturn type: NoReturn
-
add_routes
(plugin)[source]¶ Add multiple routes to the router.
Parameters: plugin – the plugin to add routes from Return type: NoReturn
-
exec_route
(request)[source]¶ Execute a route function directly
Parameters: request ( GladosRequest
) – the GLaDOS requestReturns: Return type: the data returned by the plugin Examples
>>> def mock_function(request: GladosRequest): ... print(f"Mock Function: {request.params.message}") ... return True >>> router = GladosRouter() >>> route = GladosRoute(RouteType.SendMessage, "send_mock", mock_function) >>> router.add_route(route) >>> request = GladosRequest(RouteType.SendMessage, "send_mock", message="Hello World!") >>> successful = router.exec_route(request) Mock Function: Hello World! >>> print(successful) True
>>> def mock_function(request: GladosRequest): ... print(f"Mock Function: {request.params.message}") ... return True >>> router = GladosRouter() >>> route = GladosRoute(RouteType.SendMessage, "send_mock", mock_function) >>> router.add_route(route) >>> request = GladosRequest(RouteType.SendMessage, "send_mock_fail", message="Hello World!") >>> successful = router.exec_route(request) >>> print(successful) False
-
glados.utils module¶
-
glados.utils.
check_for_env_vars
(value)[source]¶ Check an input value to see if it is an env_var or enc_env_var and get the value.
Parameters: value ( Union
[str
,dict
]) – input to check.Returns: Returns the value of the var from either the passed in value, or the env var value. Return type: Any Raises: KeyError if the env var is not set for what youre tying to get.
-
glados.utils.
decode_kms
(ciphertext_blob)[source]¶ Decode a secret using the IAM role of the lambda function.
Parameters: ciphertext_blob ( str
) – ciphertext_blob to decodeReturns: Decoded KMS data Return type: obj: str