朱门是什么意思| 长歌怀采薇是什么意思| 黄体破裂是什么原因造成的| 卯时五行属什么| 荠菜什么时候播种最好| 煮玉米加什么才会香甜| 三条杠是什么牌子| 灶性肠化是什么意思| 古代地龙是什么| 跟腱炎吃什么药效果好| 滑精是什么原因| 浪荡闲游是什么生肖| vc是什么意思| 没吃多少东西但肚子很胀是什么| 生化是什么原因引起的| 下午两点属于什么时辰| meme什么意思| hmg是什么药| EE什么意思| ba是什么| 阴历是什么| 做雪糕需要什么材料| 退着走路有什么好处| 中国国菜是什么菜| 多囊挂什么科| 阴唇发黑是什么原因| 看心理医生挂什么科| 做梦梦到乌龟是什么预兆| 精神慰藉什么意思| 长智齿牙龈肿痛吃什么药| 蝴蝶骨是什么| 夏季吃什么| 心病是什么病有哪些症状| 27岁属什么生肖| 润滑油可以用什么代替| 大美女是什么意思| 一直吐口水是什么原因| shark是什么意思| 焦糖是什么糖| 喝啤酒吃什么菜最好| 为什么会有湿气| 水土不服是什么意思| 儿童内分泌科检查什么| 这是什么皮肤病| 小腹胀痛什么原因女性| 低聚糖是什么| 疤痕体质是什么| 升学宴选什么日子好| 跑酷是什么运动| 为什么全麻手术后不能睡觉| 为什么会牙龈出血| 什么时间吃水果比较好| 慈禧属什么生肖| 小孩牙疼有什么办法| 办护照需要准备什么材料| 屁眼疼是什么原因| 晟这个字读什么| 白头发是缺什么维生素| 什么是情商高| 皲裂是什么意思| 苏武牧羊是什么意思| 血糖高什么水果能吃| 碳13和碳14有什么区别| 老人说胡话是什么征兆| 肝部出现腹水是什么原因| 乔顿男装属于什么档次| 观音菩萨保佑什么| 脑白质脱髓鞘是什么意思| 用什么药可以缩阴紧致| 1942年属什么生肖| 梦见朋友结婚是什么意思| 正常人为什么会低血糖| 碱性磷酸酶是什么意思| sla是什么意思| 甲抗是什么原因引起的| 枸杞子泡茶喝有什么好处| 受精卵着床是什么意思| 孩子肚子疼是什么原因| 子宫肥大有什么危害| 有心火是什么症状| 6像什么| 肠炎不能吃什么东西| 主人是什么意思| 手麻木什么原因| rpr是什么检查项目| 喉咙痒吃什么药好| 女人吃桃子有什么好处和坏处| 绞股蓝长什么样子| 宫颈肥大是什么原因造成的| elsa是什么意思| 丙肝为什么会自愈| 王母娘娘属什么生肖| 尿比重是什么意思| 伸什么缩什么| movies是什么意思| 流口水吃什么药最好| 什么叫入伏| 恩怨是什么意思| 什么叫收缩压和舒张压| 回迁是什么意思| 临聘人员是什么意思| 立是什么生肖| 什么怎么什么造句| ab型和o型生的孩子是什么血型| 要强是什么意思| 冰丝皱是什么面料| 生命的尽头是什么| 什么是血管瘤| 人为什么会得甲母痣| 五十年婚姻是什么婚| 螚什么意思| 义眼是什么| 眼窝凹陷是什么原因| 难耐是什么意思| 万中无一什么意思| 吃什么水果能长高| 耐克属于什么档次| 政绩是什么意思| 消症是什么意思| 耵聍是什么意思| 快递客服主要做什么| 点字五行属什么| 鹰潭有什么好玩的地方| 拉尼娜现象是什么| 上火是什么意思| 羊齿状结晶代表什么| pg在医学是什么意思| 落子无悔是什么意思| 什么兽| 母亲过生日送什么礼物| 上天眷顾是什么意思| 三围是什么| 大专有什么专业| 塑胶厂是做什么的| kms是什么药| 一度房室传导阻滞是什么意思| 甲状腺功能三项查什么| 门对门有什么说法| 因势利导什么意思| 痔疮什么症状| 双肾盂分离是什么意思| 马桶对着卫生间门有什么不好| 尿道口流脓吃什么药| rt什么意思| 板栗什么时候成熟| 摩羯座的幸运色是什么| hct是什么意思| 哺乳期感冒吃什么药不影响哺乳| 阳刚之气是什么意思| 艺体生是什么意思| 不服是什么意思| 南无阿弥陀佛什么意思| 澳门什么时候回归祖国| 雅五行属性是什么| 经常喝红茶有什么好处和坏处吗| 护士是干什么的| 阿里巴巴是干什么的| 肌酐高不能吃什么| 姚明什么时候退役的| 拉屎屁股疼是什么原因| 月令是什么意思| 怀孕挂什么科| 避孕药叫什么| 一个九一个鸟念什么| 早餐吃什么最营养| 水肿是什么病| zoe是什么意思| 男性生殖器叫什么| 静候佳音是什么意思| 河马吃什么食物| 属兔本命佛是什么佛| 画眉鸟吃什么| 无氧运动是什么| 每个月月经都提前是什么原因| 托腮是什么意思| 普字五行属什么| 陪伴是最长情的告白下一句是什么| 什么病不能吃秋葵| 牛肉烧什么菜最好吃| 女孩叫锦什么好听| 鸡精和味精有什么区别| chick什么意思| 小腿抽筋吃什么药| 做梦梦见剪头发是什么意思| 丝瓜有什么营养| 子痫是什么病| 胃烧灼感是什么原因引起的| opv是什么疫苗| 神志不清是什么意思| 目前除皱最好的方法是什么| 空亡是什么意思| leu是什么氨基酸| 总爱放屁是什么原因| 刘嘉玲什么星座| 白细胞偏低是什么原因造成的| 11号来月经什么时候是排卵期| 吃月饼是什么生肖| 绝对是什么意思| 养肝吃什么食物| 7月15日是什么星座| 肽是什么| 什么是高热量食物有哪些| 五一年属什么生肖| 生辰八字是指什么| sp是什么的缩写| 腿抖是什么病的预兆| 手足口病疫苗什么时候打| 茄子炒什么好吃| 梦特娇属于什么档次| 吃什么丰胸效果好又快| 黑豆熟地水功效是什么| 花生属于什么类食物| 司空见惯是什么意思| 脖子出汗多是什么原因女人| 什么手机有红外线功能| 梦见别人给我介绍对象是什么意思| 顺位是什么意思| 宫腔积液是什么意思| 子宫脱落是什么原因引起的| 植物园有什么植物| 11.1是什么星座| 马上风是什么意思| 侧睡流口水是什么原因| 面瘫挂什么科室| 黄疸严重会造成什么后果| 什么是牙槽骨突出图片| 伤口撒什么药粉好得快| 阴道炎有些什么症状| 月经期间喝什么汤好| 倒牙是什么意思| 吃三七粉不能吃什么| 公分的单位是什么| 红细胞是什么| 什么是结缔组织| 2005年是什么生肖| 小鬼是什么意思| 经常放屁是什么原因造成的| 小虾吃什么食物| 11月27号什么星座| 人到无求品自高什么意思| 附件炎是什么症状| 藕断丝连是什么意思| 黄芪可以和什么一起泡水喝| 孕早期吃什么水果| 耳聋吃什么药| 黄鼠狼为什么叫黄大仙| 手指抽筋是什么原因| 什么是周围神经病| 脾胃湿热吃什么药好| 耄耋是什么意思| 搭桥和支架有什么区别| 地格是什么意思| 手掌像什么| 肚脐周围痛是什么原因| 负离子是什么| 昆明的别称是什么| 次第花开是什么意思| 凝胶是什么| 六点半是什么时辰| 学前教育是什么| 独一味是什么药| 白发多的原因是什么| 中水是什么| 脚酸是什么原因引起的| 百度
Sitemap
HackerNoon.com

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

So, a few months back I created a Slack workspace for people from various walks to come together to share interesting articles, videos and podcasts — think of it as a place where you find something interesting to read from various domains such as business, education, technology and so on. People started joining and like all groups, it reached a stage where I felt the # active people were < # people in the group. I wanted to send a message to everyone asking if they’d like to continue or leave the group.

Note: If you’re interested in joining the workspace, comment below.

So, I opened Google and typed “How to send direct message to everyone in a Slack workspace”. To my surprise, there was no direct way of doing it. The only way was to create a Slack bot yourself and add a few lines of code to enable this feature — and I found no article that had the detailed procedure. I had some free time, so I thought I’d try it myself. It would also serve as a good refresher for my upcoming interviews.

Warning: I am an amateur when it comes to programming, so it took me 3 days and lots and lots and lots and lots…. of errors after which it finally worked. Hopefully, this step by step guide should make it easier for you.

Minute 1: Download Python 2.7.13 and Add To PATH

You are going to need to set up the environment before beginning to code. You need the following to create the bot and make it work:

  1. Python 2.7.13
  2. Pip and virtualenv
  3. A slack account and a workspace that you are part of

Note: I did it on my Windows laptop. The commands are slightly different if it’s on a Mac or Linux machine, so kindly check online for the appropriate changes.

That’s it. Now, follow this link to download the Python 2.7.13 version. Do not download Python 2.7 as it is not compatible with downloading the latest Pip versions.

Have you downloaded and installed? Great! Now, if you open up your Command Prompt and type Python, it will show the following:

Zoom image will be displayed

This is because the Python path has not been added to your PATH environment variable. Go to My Computer -> Properties -> Advanced System Settings -> Environment Variables. You should see the following.

Zoom image will be displayed

Click on Path and ‘Edit’. Add a new path there: C:\Python27 (assuming that’s where your Python directory is or add whatever the path is).

Now open Command Prompt and type Python. It should work!

Minute 2: Download and Install pip

Time to download pip. pip is a package management system used to install and manage software packages written in Python. Follow this link and download the get-pip.py file and save it on a new folder. This is the folder where all your files should be saved from now.

Now, open Command Prompt, navigate to the folder where the pip file is and type:

python get-pip.py

It should work and tell you that it’s successful. Now, you have to add the path to the pip file as you did before. Follow the same instructions as before and add this to your PATH environment variables: C:/Python27/Scripts (this is where the pip file is).

Now type pip in Command Prompt and it should work!

Minute 3: Install and Activate virtualenv

virtualenv is a tool to create isolated Python environments. virtualenv creates a folder which contains all the necessary executables to use the packages that a Python project would need.

Simply go to the folder where you stored your get-pip.py file and type the following:

pip install virtualenv

Once it’s installed, you need to create a new virtualenv and activate it.

virtualenv env

env\Scripts\activate

The above commands should give you the following screen:

Zoom image will be displayed
I was too attached to this project, hence the name Slack Baby

Minute 4: Create A New Slack App and Slack Bot

Now it’s time to create a bot that will do the actual task of sending messages to all members. Follow this link and go to the Slack API page. Login there with your Slack account credentials and you should see a screen like this.

Zoom image will be displayed

Once you click on Create an App, fill in the App name and choose your workspace:

Zoom image will be displayed

Now, move over to the Bot Users tab on the left and create a new bot:

Zoom image will be displayed

Once you’ve added this, you need to go to OAuth & Permissions and authorize the bot to post in your workspace:

Zoom image will be displayed

All good so far? Now, go back to OAuth & Permissions. You should see the following two tokens. These are very important and hence keep it to yourself.

Minute 5: Install Slackclient and Check If API Call Works

Open up the good old Command Prompt again (hopefully it’s still kept open), go to the folder with the pip file and type the following:

pip install slackclient

We need the SlackClient to connect to the Slack Bot. Let’s see if it works now. Copy the Bot User OAuth Access Token and keep it. Now, type python in the Command Prompt and enter the python environment.

Zoom image will be displayed

Minute 6: Time To Test The Environment

Till now, all we did was set up the environment. Now it’s time to write the actual code that will do the magic. I want you to first test if your environment works by writing a code that gets the list of all channel names in your workspace and posts that in the Prompt. Use the following code:

(Comment below to get this code + my code which will come later on)

Now, in the Command Prompt, type:

python filename.py

It should display below all the channel names in your workspace. Works? Awesome!

Minute 7: Method I: Use Dan Goldin’s Code

So, I found this blog by Dan Goldin (huge thanks to Dan!) who had written a script already that will do the job. Here is his Github code. I will show two ways you can execute the job.

First, we will use Dan’s code. Next, I will show my code.

So, hopefully you have downloaded Dan’s code and put it in the folder you’ve been using up till now.

First, we need to install requirements.txt. In your Command Prompt, exit the python environment by typing exit(). Now, type:

pip install -r requirements.txt

It should install all the packages needed!

Now, open spam_channel_members.py in IDLE (or whichever python IDE you have) and paste your token in the line

sh = SlackHelper(‘paste your token here’)

Minute 8: Method 2: Use My Code

Now, this is the final part. Type the following in the prompt:

python spam_channel_members.py your_test_channel_name your_test_message

Zoom image will be displayed

This should hopefully work!

So, I wrote a code to do the same which is shorter but probably not optimal. Here is the code:

Zoom image will be displayed

I am basically getting the list of users in the workspace using the users.list API call, extracting the members dictionary from it, and using a for loop to send messages to the member using their ID. This worked fine for me, and hope it does for you. If you need the above code, commend below and I’ll email it to you!

Once you have the above code ready in a Python file, simply go to Prompt and type:

python filename.py

That is all! It should hopefully show you a ‘Success!’ message once it’s executed and you should have sent a message to everyone in your workspace.

*******************************************************************

So hopefully that worked out for you. This was just a small project I worked on last week and thought it’d be useful if someone else wanted to do the same. If you encountered an error at any step, Stackoverflow is your best friend. I had errors at every step and it took me the longest to set up the environment. Initially, I tried to do this using Stdlib and Node.js, however, that did not work. Python to the rescue!

This is my first article where I’ve talked about a technical concept and I plan on doing this more from now. I would love to hear your comments on whether the article was articulate enough for you to understand. Thank you for reading till now. Cheers :)

If you found this enjoyable, do Follow me for more articles. I’m a sufficiently frequent writer. Here is my personal blog.

The best way to get in touch with me is via Instagram and Facebook. I share lot of interesting content there. To know more about my professional life, check out my LinkedIn. Happy reading!

--

--

HackerNoon.com
HackerNoon.com

Published in HackerNoon.com

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

Soundarya Balasubramani
Soundarya Balasubramani

Written by Soundarya Balasubramani

Writing a book to help skilled immigrants in America. Join my weekly newsletter: readunshackled.com :)

Responses (2)

痰多吃什么好 颈椎钙化是什么意思严重么 为什么小孩子经常流鼻血 农历5月25日是什么星座 尿的颜色有点红褐色是什么原因
最好的止疼药是什么药 汪字五行属什么 浅表性胃炎吃什么药好使 749局是什么 什么原因会导致尿路感染
什么情况下要做宫腔镜 血沉50说明什么原因 胃阴虚吃什么中成药 腹腔多发淋巴结是什么意思 岗位性质指的是什么
食道炎用什么药最好 八十岁叫什么之年 宫颈病变是什么意思 扁平苔藓是什么病 惊恐发作是什么病
小孩发烧呕吐是什么原因hcv7jop9ns4r.cn 3月25号是什么星座hcv9jop0ns1r.cn 新生儿黄疸高有什么风险hcv7jop5ns1r.cn imax是什么意思hcv9jop1ns6r.cn 尾骨疼痛挂什么科hcv9jop3ns5r.cn
曹休和曹操什么关系hcv9jop0ns1r.cn 女性吃大肠有什么好处hcv9jop7ns9r.cn iga是什么hcv9jop5ns4r.cn 大保健是什么意思hcv7jop4ns5r.cn 国行是什么意思hcv9jop5ns7r.cn
当归有什么作用hcv8jop0ns2r.cn 宝宝风热感冒吃什么药hcv9jop8ns1r.cn 为什么发动文化大革命hcv9jop8ns3r.cn 肾阴亏虚吃什么药hcv9jop6ns3r.cn 嘴巴有异味是什么原因hcv9jop1ns9r.cn
什么叫缘分hcv9jop7ns5r.cn 养囊是什么意思hcv7jop6ns9r.cn 一天当中什么时候血压最高hcv9jop5ns1r.cn min是什么单位sanhestory.com 拔智齿当天可以吃什么hcv8jop1ns9r.cn
百度