Slack
Sample Commands
on-slack --channel sandbox --message "Hi there!"
Sends slack messages
Source code in linecaspy/slack/slack.py
class SlackClass:
"""Sends slack messages"""
def __init__(self, param_1, param_2, workspace="TUQ4RSF96", debug=False):
"""Initializes the the Slack object to send messages
Args:
param_1 (string): First paramater in webhook URL
param_2 (string): Second paramater in webhook URL
workspace (string): ID of the Slack workspace
debug (bool): Used for pprint and log debugging
"""
self.url_param_1 = param_1
self.url_param_2 = param_2
self.workspace = workspace
self.headers = {"Content-Type": "application/json"}
self.hf = HelperFunctions()
def post_message(self, message):
"""Sends a Slack message
Args:
message (string): The contents that are desired to be sent
Returns:
string: if success, otherwise None
"""
url = f"https://hooks.slack.com/services/{self.workspace}/{self.url_param_1}/{self.url_param_2}"
data = {"text": str(message)}
logger.info(f"Posting to URL: {url}")
logger.info(f"With message: {message}")
r = requests.post(url, headers=self.headers, data=json.dumps(data), verify=True, timeout=5.0)
self.hf.debug_requests_results(r)
if r.status_code == 200:
return r.text
else:
return None
__init__(self, param_1, param_2, workspace='TUQ4RSF96', debug=False)
special
Initializes the the Slack object to send messages
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param_1 |
string |
First paramater in webhook URL |
required |
param_2 |
string |
Second paramater in webhook URL |
required |
workspace |
string |
ID of the Slack workspace |
'TUQ4RSF96' |
debug |
bool |
Used for pprint and log debugging |
False |
Source code in linecaspy/slack/slack.py
def __init__(self, param_1, param_2, workspace="TUQ4RSF96", debug=False):
"""Initializes the the Slack object to send messages
Args:
param_1 (string): First paramater in webhook URL
param_2 (string): Second paramater in webhook URL
workspace (string): ID of the Slack workspace
debug (bool): Used for pprint and log debugging
"""
self.url_param_1 = param_1
self.url_param_2 = param_2
self.workspace = workspace
self.headers = {"Content-Type": "application/json"}
self.hf = HelperFunctions()
post_message(self, message)
Sends a Slack message
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message |
string |
The contents that are desired to be sent |
required |
Returns:
| Type | Description |
|---|---|
string |
if success, otherwise None |
Source code in linecaspy/slack/slack.py
def post_message(self, message):
"""Sends a Slack message
Args:
message (string): The contents that are desired to be sent
Returns:
string: if success, otherwise None
"""
url = f"https://hooks.slack.com/services/{self.workspace}/{self.url_param_1}/{self.url_param_2}"
data = {"text": str(message)}
logger.info(f"Posting to URL: {url}")
logger.info(f"With message: {message}")
r = requests.post(url, headers=self.headers, data=json.dumps(data), verify=True, timeout=5.0)
self.hf.debug_requests_results(r)
if r.status_code == 200:
return r.text
else:
return None