I am new to Rasa stack and trying to build sample bot using Rasa core. I want to identify user who pinged the Rasa Bot server from Slack . I want to get either slack username or slack user’s email address, so that I can use that information for further processing such as authentication or retrieve relevant information for the email from database.
this might be contained in the tracker.sender_id
? otherwise you have to take a look at their API as to how to extract that
Hi, have you found a way to do this? I’m looking for the same thing, it would be helpful if you could share how you went about doing this, thanks.
@Shank Way to get username and email id of the user from slack. You need to define slack_client beforehand
def slackitems(tracker):
username = tracker.sender_id
print("username", username)
userinfo = slack_client.api_call("users.info", user=username)
emailid = userinfo['user']['profile']['email']
return emailid
I’m not sure I completely understand what you mean when you say slack_client but I will look it up, thanks.
Let me try to explain that. Below is the full code snippet which i will use to get mail id or username inside my actions.
from slackclient import SlackClient
SLACK_BOT_TOKEN = "token from slack app"
slack_client = SlackClient(SLACK_BOT_TOKEN)
def slackitems(tracker):
username = tracker.sender_id
print("username", username)
userinfo = slack_client.api_call("users.info", user=username)
emailid = userinfo['user']['profile']['email']
return username, emailid
class MAILING(Action):
def name(self):
return 'action_mailing'
def run(self, dispatcher, tracker, domain):
userid, mailid = slackitems(tracker)
print("userid & mailid of the user who pinged via slack is {0} & {1}".format(username, mailid))
Thank you so much. I had no idea a module called slackclient existed. This is really helpful, thanks again.
I have similar problem but I want to extract username from my own website which asks for username and password at the time of visiting the website. I am using webchat interface from this link(GitHub - botfront/rasa-webchat: A chat widget for Rasa and Botfront). How to do that?
hey @chiqui_hm, try the below code for getting user info from slack API’s using python