Post File to Slack Using Python
Akhil Sharma -> https://akhilsharma.work

Post File to Slack Using Python

Hey there! Today, I'm here to discuss one of the several ways we have to post a file to slack channel. We can write script for the same in a lot of languages like PowerShell, Python, etc. And today, I'll be discussing this using Python.

Script:

my_file = {
	  'file' : (<pathToFile>, open(<pathToFile>, 'rb'), '<typeOfFile>')
	}
	

	payload={
	  "filename":"<FileNameYouWishToShowInSlackMessage>.<ExtensionOfFile>", 
	  "token":'<SlackToken>', 
	  "channels":['#<SlackChannelName>'], 
	}
	

	r = requests.post("https://slack.com/api/files.upload", params=payload, files=my_file)

Read complete blog on: https://akhilsharma.work/post-file-to-slack-using-python/

Please feel free to reach me out incase of any help or queries, I'll be glad to help!

Thanks!

Akhil Sharma

DevOps Lead | Azure Content Hero | Architect Professional | DevOps Expert | Azure Admin | GCP Architect Professional | CKA | CKAD | CKS | KCNA | CJE | Mentor | Blogger | Speaker | Author | 150+ Calls on Topmate

4 年
回复

要查看或添加评论,请登录

Akhil Sharma的更多文章

社区洞察

其他会员也浏览了