Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c8ee8d8

Browse files
committed
🙈 Version 2.0 complete
2 parents 0565ee2 + 33e0458 commit c8ee8d8

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

docs/Chapter-3.md

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ If you open up this branch's [bot.py](bot.py) file you'll find some changes. Now
66

77
We can store bits of information we'll want to access later as attributes on the bot object and actions we want our bot to take as methods.
88

9-
### Init Your Bot's Identity
10-
11-
In the `__init__` function of the Bot class, which (as the name suggests) initializes the bot, we're giving our bot a touch of identity. Feel free to change the name and emoji here!
12-
139
Instead of importing the `python-slackclient` library in our `app.py` file like we did before, we'll import it into this file and access the `SlackClient` through an attribute on our bot. This makes it easier to handle OAuth since our bot object's attributes can be accessed in the other places it will live, such as the `app.py` file.
1410

1511
### Teach Bot How to Auth
@@ -38,7 +34,7 @@ If you peek on over at `app.py` again you'll see we've updated your `/thanks` ro
3834

3935
Now that we've been authorized, let's teach our bot to respond to users who want to say hello!
4036

41-
Earlier ,we subscribed to the Slack Events API endpoint called [message.channels](https://api.slack.com/events/message.channels). We'll listen for these events, check to see if anyone is saying hello to our bot, and then build a method on our Bot class to respond.
37+
Earlier, we subscribed to the Slack Events API endpoint called [message.channels](https://api.slack.com/events/message.channels). We'll listen for these events, check to see if anyone is saying hello to our bot, and then build a method on our Bot class to respond.
4238

4339
### Event Handlers
4440

@@ -63,23 +59,26 @@ def event_handler(event_type, slack_event):
6359
# using regex, search for 'hello' in the users' text
6460
hello_match = re.search('hello', users_text)
6561
if bot_mention_match and hello_match:
66-
# identify who said hello
67-
user_id = slack_event["user"]
6862
# and have your bot respond
69-
mybot.say_hello(user_id)
63+
mybot.say_hello()
7064
```
7165

7266
### Bot Response Methods
7367

7468
Once `app.py` holds a function to handle the `message` events we want our bot to respond to, we'll need to build a method on our `Bot` class to respond.
7569

76-
In `bot.py` you'll see we've started a method called `say_hello` to respond to a user's message in the `#general` channel. Since we already know that we want to say hello at this point, what we'll need to do is get the `user_id` that we've passed as a parameter and build a call to the Slack API's `chat.postMessage` endpoint.
70+
In `bot.py` you'll see we've started a method called `say_hello` to respond to a user's message in the `#general` channel. At this point we'll need to call to the Slack API's `chat.postMessage` endpoint to send our response.
7771

7872
It should look something like this:
7973

8074
_bot.py_
8175
```python
82-
check
76+
def say_hello(self):
77+
""" A method to respond to a user who says hello. """
78+
hello_response = "I want to live! Please build me."
79+
self.client.api_call("chat.postMessage",
80+
channel="#general",
81+
text=hello_response)
8382
```
8483

8584
Let's start our app back up again and test that it's working in the browser! Double check that your virtual environment is turned on, your secrets are exported to the environment and your ngrok tunnel is open.
@@ -96,13 +95,9 @@ Once you've installed your bot successfully, invite your bot to the `#general` c
9695

9796
## You Did It! :sparkles:
9897

99-
You should have a working bot! If you're looking for ways to make your bot fancier, look into adding more interaction with [message buttons](https://api.slack.com/docs/message-buttons) or integrating some NLP with a lovely service like [api.ai.](https://api.ai/)
100-
101-
We can't wait to see what you build next!
102-
103-
Thanks for joining us!
98+
You should have a working bot! If you're looking for ways to make your bot fancier, we'll go over adding more interaction with [message buttons](https://api.slack.com/docs/message-buttons) and integrating some NLP with a lovely service like [api.ai](https://api.ai/) in the next two chapters.
10499

105100
---
106101
###### Documentation Navigation
107-
**Next [Give Us Feedback!](https://goo.gl/forms/8FlqD5roZtCl7wx92)**
102+
**Next [Chapter 4](./../docs/Chapter-4.md)**
108103
**Previous [Chapter 2](./../docs/Chapter-2.md)**

0 commit comments

Comments
 (0)