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

Install bot to a team event #6

Closed
vovanmozg opened this issue Apr 15, 2016 · 3 comments
Closed

Install bot to a team event #6

vovanmozg opened this issue Apr 15, 2016 · 3 comments

Comments

@vovanmozg
Copy link

vovanmozg commented Apr 15, 2016

I need to send initial message to the user after adding my application to his team.
I solve this problem with is monkey patching of the file https://github.com/dblock/slack-bot-server/blob/22a215eec2/slack-bot-server/api/endpoints/teams_endpoint.rb after team activating

# == My code start ==
SlackBotServer::Service.start!(team)

client.token = rc['access_token']
information = client.auth_test({token: rc['access_token']})

client2 = Slack::Web::Client.new(token: token)
# always try to create new DM
new_dm = client2.im_open(user: information[:user_id])
channel_id = new_dm.channel.id

# send message
client2.chat_postMessage(
  channel: channel_id,
  text: "Hello <@#{information[:user_id]}>. Nice to meet you! Type 'help'",
  as_user: true
)

client2 = nil
# == My code end ==

Is there right way, to send message to user immediately after he install the bot? Can you give me advice on how to do better, or leave like that?

thanks

@dblock
Copy link
Collaborator

dblock commented Apr 15, 2016

I don't think there's a "right" way at this point. You probably want to do this in a callback after a connection has been established the first time on start, to avoid re-creating a connection twice, then remember that you sent a welcome message. But this works too.

@dblock
Copy link
Collaborator

dblock commented Apr 15, 2016

I'll leave this open, I'd like an "official" way of doing this, but probably mostly in https://github.com/dblock/slack-ruby-bot.

@dblock
Copy link
Collaborator

dblock commented Jul 1, 2016

I've implemented lifecycle callbacks in dblock@325eb94 and dblock@3bfcb30. You should be able to do this:

instance = SlackRubyBotServer::Service.instance

instance.on :created do |team, server, error|
  server.client....
end

I think we need to make .client public in slack-ruby-bot. There's a discussion about this in https://github.com/dblock/slack-ruby-bot/issues/63, would love a PR.

Give it a try?

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

No branches or pull requests

2 participants