Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""File upload
Args:
**kwargs:
filepath: (String) optional filepath to check for files to upload
Returns:
"""
print("[*] doing post message")
try:
self.inst.login()
team_id = self.inst.teams.get_team_by_name(self.team_name)['id']
channel_id = self.inst.channels.get_channel_by_name(
channel_name=self.channel_name, team_id=team_id)['id']
except exceptions.NoAccessTokenProvided as er:
print(f"[!] NoAccessTokenProvided {er}")
logger.exception()
except exceptions.InvalidOrMissingParameters as er:
print(f"[!] InvalidOrMissingParameters {er}")
logger.exception()
try:
if isfile(self.filepath):
file_ids = [
self.inst.files.upload_file(
channel_id=channel_id, files={
'files': (
basename(
self.filepath), open(
join_abs(
self.filepath), 'rb'))})['file_infos'][0]['id']]