Comments (7)
The say method is implemented here and is a wrapper on message which itself calls send_json which itself calls send_data to the slack connected real-time socket.
What you're looking for is slack RTM docs on sending message, which explains the requirements for doing so.
Other methods are documented in RTM parts of slack-ruby-client.
I would greatly appreciate any README contributions that do a good job at linking/explaining this!
from slack-ruby-bot.
Just a follow up question, my app was actually created through the steps of the
slack-ruby-server
gem, because I didn't want to have a legacy app. However if i got you right i'm still using the "old" RTM API with thesay
method, right?
yes
from slack-ruby-bot.
Sorry it took me a while to get back to you. I looked at the implementation of the say
method prior to making this issue but didnt find the message method, so thank you very much on that clarification.
Just a follow up question, my app was actually created through the steps of the slack-ruby-server
gem, because I didn't want to have a legacy app. However if i got you right i'm still using the "old" RTM API with the say
method, right?
from slack-ruby-bot.
Hey its been a while. I've started writing something for the readme on my forked repo, and I've taken the liberty to create an index and i was wondering if that's okay or if its outside of the scope of what you're looking for.
Also, this issue made me delve deeper into the code of the gem trying to figure out whats going on. I noticed that SlackRubyBot
's client
inherits from Slack::Realtime::Client
so we have access to some parts of the API
namely message
, message_id
, ping
, and typing
which is fine. However Slack::Realtime::Client
has an attribute named web_client
which is basically an instance of Slack::Web::Client
which in turn grants me access to the API::Endpoints
. Therefore i can change the above snippet to the following to achieve my desired result:
class Broadcast < SlackRubyBot::Commands::Base
def self.call(client, data, _match)
channels = client.web_client.channels_list
# parse the response and get the 'general' ch id
subs = Subscription.all()
subs.each do |sub|
client.say(channel: general_channel_id, text: "<@#{sub.user_id}>")
end
end
end
Is this intentional? Am i supposed to use the web_client
attribute?
from slack-ruby-bot.
Hey its been a while. I've started writing something for the readme on my forked repo, and I've taken the liberty to create an index and i was wondering if that's okay or if its outside of the scope of what you're looking for.
You mean a TOC? You should add https://github.com/dblock/danger-toc and it will auto-generate and enforce one for you.
Also, this issue made me delve deeper into the code of the gem trying to figure out whats going on. I noticed that
SlackRubyBot
'sclient
inherits fromSlack::Realtime::Client
so we have access to some parts of theAPI
namelymessage
,message_id
,ping
, andtyping
which is fine. HoweverSlack::Realtime::Client
has an attribute namedweb_client
which is basically an instance ofSlack::Web::Client
which in turn grants me access to theAPI::Endpoints
. Therefore i can change the above snippet to the following to achieve my desired result:class Broadcast < SlackRubyBot::Commands::Base def self.call(client, data, _match) channels = client.web_client.channels_list # parse the response and get the 'general' ch id subs = Subscription.all() subs.each do |sub| client.say(channel: general_channel_id, text: "<@#{sub.user_id}>") end end endIs this intentional? Am i supposed to use the
web_client
attribute?
This is intentional. We hold the token that lets you call the Web API, so .web_client
makes it easy. So in your case you call a web api to get a list fo channels, and it's A-OK.
Note that say
sends the data over an already open websocket, while web_client
will open a new connection every time you call an API (reuse is addressed in slack-ruby/slack-ruby-client#322), which makes it is significantly slower.
from slack-ruby-bot.
One more note, channels_list
is a paginated API and in the example above you only get page 1 that might not contain #general
. If you do paginate, depending on how many channels you have this is very slow.
The web API web_client.chat_postMessage
supports '#general'
AFAIK, so I would rewrite the code above to do web_client.chat_postMessage(channel: '#general', ...)
and I think that's that.
from slack-ruby-bot.
You mean a TOC? You should add https://github.com/dblock/danger-toc and it will auto-generate and enforce one for you.
Yes! That's exactly what i meant.
Thank you so much, everything is clearer now :)
from slack-ruby-bot.
Related Issues (20)
- Getting lots of 429 rate limit errors on https://slack.com/api/rtm.start calls HOT 7
- Graceful shutdown HOT 1
- Testing other code execution inside a command HOT 8
- Deployment tutorial needs update HOT 2
- DMing self produces Sorry @Slackbot, I don't understand that command! HOT 1
- Migration to non-legacy bots HOT 6
- Consider splitting RSpec shared behaviours and development dependencies HOT 4
- Remove support for Giphy
- Extract attachments text
- without mention in channel bot can't reply HOT 1
- Upload a file? HOT 1
- Pongbot does not run on linux mint 19 HOT 4
- Testing for two outputs from a command HOT 5
- When a command is posted in thread, its again posted as direct message automatically HOT 4
- is there an example for how to implement a conversational bot using slack-ruby-bot? HOT 1
- Missing concurrency - Add faye-websocket to your gemfile -- It's already in my Gemfile HOT 1
- Clarification of MIGRATION.md HOT 8
- Is this repo really legacy, there is still a use case? HOT 3
- Repeated 429 (ratelimited) errors from slack HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slack-ruby-bot.