scrapinghub / slackbot

A chat bot for Slack (https://slack.com).
MIT License
1.26k stars 394 forks source link

Add user property #110

Open nikitaborisov opened 7 years ago

nikitaborisov commented 7 years ago

I wanted to get the name of the user who sent me a message so that I could, for example, say "Hello, FirstName", so I created a user property for Message . Now this code works:

@respond_to("Hello", re.IGNORECASE)
def hello(message):
    message.reply("Hello, {}!".format(message.user["profile"]["first_name"]))
roperi commented 7 years ago

@nikitaborisov, @lins05

Thanks! These are great ideas!

There should be a better way to load some non-Slack information that belongs exclusively to the user in a Team so the bot can provide her/him with ad-hoc data. Example: a user in a team wants to know if her holiday application was approved by the company.

#load user data
user_data = get_data_from_database(message.user['profile']['first_name'])
#user_data = {"name": "Jane", "team_id:" 133, 'holiday_application_status': 'Approved', ...}
message.reply("Your holiday application was {}".format(user_data["holiday_application_status"]))

At the moment 'message.user' seems a bit counter-intuitive. What do you think?

manicmaniac commented 7 years ago

@nikitaborisov, @lins05

This change looks cool but I think self._body['user'] may cause a problem because bot doesn't have user key in their message body.

jtatum commented 7 years ago

Rather than using the API to poll users, it would be cool if it used the profile information captured during rtm.start and kept it updated using the mechanism from #117. Once it's merged, we'd need to add a handler for user.change as well to keep the stored profile data current. Then there's no need to make api calls for data that slack has already told us about.

lins05 commented 7 years ago

ping @nikitaborisov

jtatum commented 7 years ago

Recent changes to bot code should keep the _client.users dict updated with current user data, including slack profile info. Using the API shouldn't be required. Please rebase changes against latest code, then remove usage of the web api to retrieve user info.