Class: Waylon::Slack::Message
- Inherits:
-
Object
- Object
- Waylon::Slack::Message
- Includes:
- Message
- Defined in:
- lib/waylon/slack/message.rb
Overview
A representation of Slack messages for Waylon
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#author ⇒ User
The User that authored this Message.
-
#channel ⇒ Channel
The Channel where this Message was sent.
-
#initialize(id, data = {}) ⇒ Message
constructor
A new instance of Message.
-
#mentions_bot? ⇒ Boolean
Does the message text mention the bot?.
-
#part_of_thread? ⇒ Boolean
Is this Message a reply in a thread?.
-
#private_message? ⇒ Boolean
(also: #private?)
Is this a private Message / direct Message?.
-
#react(reaction) ⇒ void
Uses the Sense’s Web Client to add a reaction to a Message.
-
#sense ⇒ Class
Easy access to the Sense class.
-
#text ⇒ String
(also: #body)
The unescaped contents of the Message.
-
#thread_parent ⇒ String
The TS value of the parent of this Message’s thread, or its own TS if it is the parent.
-
#thread_ts ⇒ String?
The TS value of the parent of this Message’s thread, if it exists.
-
#to_bot? ⇒ Boolean
Does this Message either directly mention or is it directly to this bot?.
-
#ts ⇒ String
This Message’s own TS value (which should not be used for threading if it itself is a thread reply).
Constructor Details
#initialize(id, data = {}) ⇒ Message
Returns a new instance of Message.
11 12 13 14 |
# File 'lib/waylon/slack/message.rb', line 11 def initialize(id, data = {}) @id = id @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
9 10 11 |
# File 'lib/waylon/slack/message.rb', line 9 def data @data end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/waylon/slack/message.rb', line 9 def id @id end |
Instance Method Details
#author ⇒ User
The User that authored this Message
18 19 20 |
# File 'lib/waylon/slack/message.rb', line 18 def User.new(data["user"]) end |
#channel ⇒ Channel
The Channel where this Message was sent
24 25 26 |
# File 'lib/waylon/slack/message.rb', line 24 def channel Channel.new(data["channel"]) end |
#mentions_bot? ⇒ Boolean
Does the message text mention the bot?
30 31 32 33 34 |
# File 'lib/waylon/slack/message.rb', line 30 def mentions_bot? me = User.whoami reg = /(,\s+)?\s*@#{me.id},?\s*/ ::Slack::Messages::Formatting.unescape(data["text"]) =~ reg ? true : false end |
#part_of_thread? ⇒ Boolean
Is this Message a reply in a thread?
38 39 40 |
# File 'lib/waylon/slack/message.rb', line 38 def part_of_thread? thread_ts && thread_ts != ts end |
#private_message? ⇒ Boolean Also known as: private?
Is this a private Message / direct Message?
44 45 46 |
# File 'lib/waylon/slack/message.rb', line 44 def channel.private? end |
#react(reaction) ⇒ void
This method returns an undefined value.
Uses the Sense’s Web Client to add a reaction to a Message
53 54 55 |
# File 'lib/waylon/slack/message.rb', line 53 def react(reaction) sense.client.reactions_add(channel: channel.id, name: reaction, timestamp: ts) end |
#sense ⇒ Class
Easy access to the Sense class
59 60 61 |
# File 'lib/waylon/slack/message.rb', line 59 def sense ::Waylon::Senses::Slack end |
#text ⇒ String Also known as: body
The unescaped contents of the Message
65 66 67 68 69 |
# File 'lib/waylon/slack/message.rb', line 65 def text me = User.whoami reg = /(,\s+)?\s*@#{me.id},?\s*/ ::Slack::Messages::Formatting.unescape(data["text"]).gsub(reg, "") end |
#thread_parent ⇒ String
The TS value of the parent of this Message’s thread, or its own TS if it is the parent
75 76 77 |
# File 'lib/waylon/slack/message.rb', line 75 def thread_parent thread_ts || ts end |
#thread_ts ⇒ String?
The TS value of the parent of this Message’s thread, if it exists
81 82 83 |
# File 'lib/waylon/slack/message.rb', line 81 def thread_ts data["thread_ts"].dup end |
#to_bot? ⇒ Boolean
Does this Message either directly mention or is it directly to this bot?
87 88 89 |
# File 'lib/waylon/slack/message.rb', line 87 def to_bot? data["type"] == "app_mention" || end |
#ts ⇒ String
This Message’s own TS value (which should not be used for threading if it itself is a thread reply)
93 94 95 |
# File 'lib/waylon/slack/message.rb', line 93 def ts data["ts"].dup end |