Closed ghost closed 3 years ago
What's the rest of that stack trace? I bet this isn't coming from the library and the data in event
is different. Do this:
SlackRubyBotServer::Events.configure do |config|
config.on :event, ['event_callback', 'team_join'] do |event|
begin
client = Slack::Web::Client.new(token: team_token(event[:event][:team]))
user = client.users_info(user: event[:event][:user])
unless user[:user][:is_bot] || team.users.exists?(user_id: event[:event][:user])
team.users.create(user_id: event[:event][:user], user_name: user[:user][:name])
#event.answer(blocks: WelcomeMessage.blocks) unless debug?
event.logger.info "team_join #{event[:event][:user]} #{user[:user][:name]}"
end
nil
rescue Slack::Web::Api::Errors::SlackError => e
p e
p e.backtrace
raise
end
end
If this shows a better exception with the line that actually raised it, we need to do something in the code that invokes callbacks to help the caller find the culprit.
According to the documentation, event[:event][:user]
is a hash, probably containing id
, so users_info(user: event[:event][:user])
is incorrect and should be something like users_info(user: event[:event][:user][:id])
?
I just added a rescue section, after the holidays I will test and report the result.
The problem is that, as I said, users_info(user: event[:event][:user])
works correctly for other events except only this one, but I'll try to check that too.
Error caused by line user = client.users_info(user: event[:event][:user])
. As I can see, I need to use event[:event][:user][:id] there? If that so, it's strange, because I don't need to add [:id] in other events. Anyway, I will check it later and inform you.
Well, these are different APIs.
member_joined_channel sends
{
"type": "member_joined_channel",
"user": "W06GH7XHN",
"channel": "C0698JE0H",
"channel_type": "C",
"team": "T024BE7LD",
"inviter": "U123456789"
}
team_join sends
{
"type": "team_join",
"user": {
…
}
}
So really just apples and oranges.
I'll close this since we found the problem, but feel free to ask more questions here if you would like.
There was a comment that was edited to remove the key, I deleted it. The user seems to be deleted from GitHub unfortunately so we'll never know who it was.
Great. I'm going to delete my original comment now too!
I am trying to create a simple bot for greetings. According to the instructions in the Slack API, I need to process the "team_join" event. But while processing it, I get the error:
This is the code I use to process event:
Please ignore the commented line: this is my simple wrapper to quickly respond in events and in both cases it was commented out.
It is interesting that by copying the same code into the "member_join_channel" handler, everything works good.