汗血宝马什么意思| 青菜是什么菜| 漏斗胸是什么原因造成的| 命里缺金取什么名字好| 孕妇建档需要什么资料| r的平方是什么意思| 口苦吃什么药| 醋精和白醋有什么区别| 哺乳期能吃什么水果| 什么津津| 赤道2什么时候上映| 蒙奇奇是什么动物| 什么动物跑得快| 芭乐是什么季节的水果| 腈纶是什么面料优缺点| 剑锋金命五行缺什么| 男生13厘米属于什么水平| 好记性不如烂笔头是什么意思| 看心脏病挂什么科| 城市的夜晚霓虹灯璀璨是什么歌| 梦见吃葡萄是什么意思| 每天吃一个西红柿有什么好处| 智齿发炎挂什么科| 桃符指的是什么| 婴儿半夜哭闹是什么原因| 沙门氏菌用什么药最好| 医保报销是什么意思| 口腹蜜剑什么意思| 吃什么东西化痰| 结界是什么意思| coco什么意思| 北瓜是什么瓜| 清水文是什么意思| 湛江有什么好吃的| 观音菩萨成道日是什么意思| 女性生活疼痛什么原因| 女生的逼长什么样| 头部容易出汗是什么原因| 五个月宝宝吃什么辅食最好| 顾名思义什么意思| 吃烧烤后吃什么水果可以帮助排毒| 查胃病做什么检查合适| 幽门螺杆菌什么药最好| 樟脑丸是干什么的| vd是什么| 秦昊的父母是干什么的| 来月经前有什么症状| 湿气太重吃什么好| 堃读什么| 肩胛骨突出是什么原因| 关节退行性改变是什么意思| 远在天边近在眼前是什么意思| 陶渊明什么朝代| 过氧化氢弱阳性什么意思| 减肥期间可以吃什么| 调理月经吃什么药最好| a9什么意思| 硼砂是什么东西| 王朔为什么不娶徐静蕾| 什么茶降尿酸| 肠易激综合症什么症状| 无赖不还钱最怕什么| 逸事是什么意思| 铁观音茶属于什么茶| cyl是什么意思| 血常规是什么| 舌根苔白厚腻是什么原因| 一冷就咳嗽是什么原因| 滔滔不绝的绝是什么意思| 悄悄的什么| 懵懂是什么意思| 鸠是什么鸟| 金字旁加巨念什么| 一线炎是什么病严重吗| 巨蟹是什么星座| 糗事是什么意思| 新生儿老是打嗝是什么原因| focus什么意思| 小孩长白头发是什么原因| 再生障碍性贫血是什么病| 舌系带挂什么科| 阴道红肿是什么原因| 干姜和生姜有什么区别| 积食吃什么食物帮助消化| 手麻去医院挂什么科| 抑郁什么意思| 应接不暇的暇是什么意思| 蛇盘疮吃什么药| 扩张是什么意思| 黄果树是什么树| 荭是什么意思| 心率偏高是什么原因| 为什么不能下午看病人| 仪字五行属什么| 胺试验阳性是什么意思| 抗体是什么意思| 肾囊肿是什么原因引起的| 零八年属什么生肖| 机油用什么能洗掉| 蚂蟥是什么| 金达克宁和达克宁有什么区别| 孕妇口腔溃疡能用什么药| 宝宝蛋白质过敏喝什么奶粉| 女生来大姨妈要注意什么| 释迦果吃了有什么好处| 豫州是现在的什么地方| 脾五行属什么| 扁桃体炎吃什么药最好| 青金石蓝是什么颜色| 吃什么好| 处女膜破了什么症状| 后背疼是什么原因| 太原为什么叫龙城| 梦见自己的手机丢了是什么意思| 吃芒果过敏是什么症状| 副研究员什么级别| 阴道瘙痒是什么原因造成的| 贲门炎吃什么药| 糖尿病患者适合吃什么水果| 蚝油可以用什么代替| 吃红枣有什么好处| 三伏天晒背有什么好处| 农历7月25日是什么星座| 肾上腺增生是什么意思| 软开是什么| 叉烧是什么| 大生化能查出什么病来| 斐乐手表属于什么档次| 落井下石什么意思| 四大菩萨分别保佑什么| bb霜和粉底液有什么区别| 尾盘放量拉升意味着什么| 益母草颗粒什么时候喝| 高反人群一般是什么人| 苏东坡属什么生肖| 电饭锅内胆什么材质好| co什么意思| 立加羽念什么| 腿肿是什么原因引起的怎么办| 孕妇吃鸡蛋对胎儿有什么好处| 血沉高意味着什么意思| 番茄什么时候种植| 211是什么意思| 竖心旁与什么有关| 泰坦尼克号什么时候上映的| 什么叫会车| 三十岁是什么之年| 痛风吃什么消炎药| 头晕出虚汗是什么原因引起的| opi是什么意思| 手指尖疼是什么原因| 马躺下睡觉为什么会死| 馀是什么意思| 2024年是什么年| 什么鱼不属于发物| 从容面对是什么意思| 放疗是什么| 动情是什么意思| 预防更年期提前应该吃点什么药| 3月6日是什么星座| 身份证号码最后一位代表什么| 什么是裸眼视力| 乳房痛什么原因| 早搏什么意思| 鳏寡孤独是什么意思| 阿奇霉素和头孢有什么区别| 上半身胖属于什么体质| 中国特工组织叫什么| 什么的粽子| 长痘吃什么水果好| 霉菌性阴炎用什么药止痒效果好| 狗牯脑茶属于什么茶| 早上起来口干口苦是什么原因| 咳嗽喝什么汤好| 治安大队是干什么的| 女人阴虚火旺吃什么药| 手串什么材料的最好| 省委组织部长是什么级别| 肠胃型感冒吃什么药| 肝脏低回声意味着什么| 韬光养晦是什么意思| 相形见拙什么意思| 荔枝有什么作用与功效| 哈达是什么意思| 抖是什么意思| 小孩掉头发是什么原因| 月经不调去医院挂什么科| 养猫有什么好处| 妃子笑是什么茶| 抱怨是什么意思| 霍建华为什么娶林心如| 二尖瓣反流吃什么药| 纳呆是什么意思| 腱鞘炎是什么引起的| 汗血宝马什么意思| 两个火念什么| rh血型阴性是什么意思| 老年人腿脚无力是什么原因| 急性肠胃炎可以吃什么食物| 蝉为什么要脱壳| 五谷是什么| 猎德村为什么那么有钱| 看肝挂什么科| 先兆性流产是什么症状| 克罗心是什么牌子| 体内湿热吃什么中成药| 磷高有什么症状和危害| 后期是什么意思啊| 2010年是什么生肖| 大骨节病是一种什么病| 下焦湿热是什么意思| 番薯是什么| 生育津贴什么时候到账| 1882年属什么生肖| 睡美人最怕什么| 嘴突然歪是什么原因造成的| hyper是什么意思| 脾胃不好能吃什么水果| 农历四月是什么月| 2月20是什么星座| 浅表性胃炎是什么意思| 1898年属什么生肖| 痛风喝酒会有什么后果| 志愿号是什么意思| 什么是马上风| 什么是盆地| 孕妇吸氧对胎儿有什么好处| 这个是什么表情| 刚生完孩子的产妇吃什么好| 心脏早搏吃什么药效果好| 什么样的夜晚| 培根是什么肉做的| 爱情的本质是什么| 袋鼠是什么动物| 胃蛋白酶原1偏低是什么意思| 省委巡视组组长什么级别| 息斯敏是什么药| 喘不上来气是什么原因| 黄体酮不足吃什么| 理疗和按摩有什么区别| 乙状结肠管状腺瘤是什么意思| 薄荷叶有什么功效| cpa是什么意思| 脑梗吃什么药好| 喝茶为什么睡不着觉| 电动车是什么电池| 冬至吃什么馅的饺子| 神的国和神的义指的是什么| 不安是什么意思| 尿次数多是什么原因| 美国为什么那么强大| 体检前三天不能吃什么| 来大姨妈喝红糖水有什么作用| 滞是什么意思| 小腹痛吃什么药| 殿后和垫后有什么区别| 白细胞30是什么意思| 早期流产是什么症状| 传染源是什么| 动物园里面有什么动物| 泥灸是什么| camus是什么酒| 肝病有什么征兆| 区间放量是什么意思| 百度
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)

腋毛上有白色附着物是什么 兔死狐悲指什么生肖 耳石症是什么症状 a醇对皮肤有什么作用 女右眉毛跳是什么预兆
主任科员是什么级别 什么凝视 着重号是什么符号 脾大是什么原因造成的怎么治疗 护照需要什么材料
疱疹有什么症状表现 予字五行属什么 灰枣和红枣有什么区别 鼻子一直流血是什么原因 农历和阳历有什么区别
树蛙吃什么 逆熵是什么意思 tf是什么意思 吃激素有什么副作用 吃过敏药有什么副作用
睾丸变小是什么原因beikeqingting.com 拖什么东西最轻松hcv9jop3ns3r.cn 糖醋鱼用什么鱼hcv7jop9ns3r.cn 脚后跟痛是什么原因onlinewuye.com 喝酒脸红是缺少什么酶96micro.com
尿道感染用什么药hcv9jop5ns6r.cn 属狗的本命佛是什么佛zhongyiyatai.com get什么意思hcv8jop8ns1r.cn zutter是什么意思hcv8jop3ns4r.cn 苯丙酮尿症是什么hcv8jop0ns3r.cn
月经来的少是什么原因hcv9jop4ns5r.cn 什么什么的太阳hcv7jop5ns4r.cn 螚什么意思hcv8jop9ns1r.cn 红眼病是什么原因引起的hcv7jop5ns5r.cn 喝什么可以减肥wuhaiwuya.com
迎春花是什么颜色的hcv8jop7ns8r.cn 生脉饮适合什么人喝hcv9jop4ns6r.cn 男人吃生蚝补什么hcv8jop6ns6r.cn 下身瘙痒是什么原因hcv9jop6ns3r.cn 什么牙什么嘴hcv8jop3ns0r.cn
百度