Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user property #110

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

nikitaborisov
Copy link

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"]))

* develop:
  Stop recommending ``sudo pip install``
user = self.webapi.users.info(userid)
if not user.successful:
raise RuntimeError(user.error)
return user.body["user"]
Copy link
Collaborator

@lins05 lins05 Sep 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about caching the user info in a dict to avoid getting it back from slack web api for each time? We can add an expiration time to avoid out of date user info.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea—I'll see if I can improve it. By the way, any suggestions for how to write a test case for this? I haven't completely understood how you've set up the test environment.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtatum has written the detailed steps to run the tests in a dedicated slack team, you can read it here: https://github.com/lins05/slackbot/blob/develop/CONTRIBUTING.md#configure-tests

@roperi
Copy link

roperi commented Sep 24, 2016

@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
Copy link

manicmaniac commented Sep 29, 2016

@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
Copy link
Collaborator

jtatum commented Apr 8, 2017

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
Copy link
Collaborator

lins05 commented May 28, 2017

ping @nikitaborisov

@jtatum
Copy link
Collaborator

jtatum commented Jun 14, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants