Class: Teams::Activity
- Inherits:
-
Object
- Object
- Teams::Activity
- Defined in:
- lib/teams/activity.rb
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #channel_data ⇒ Object
- #channel_id ⇒ Object
- #conversation ⇒ Object
- #entities ⇒ Object
- #from ⇒ Object
- #get_account_mention(account_id) ⇒ Object
- #get_mentions ⇒ Object
- #get_quoted_messages ⇒ Object
- #id ⇒ Object
-
#initialize(raw = {}) ⇒ Activity
constructor
A new instance of Activity.
- #install_update? ⇒ Boolean
- #invoke? ⇒ Boolean
- #local_timestamp ⇒ Object
- #locale ⇒ Object
- #message? ⇒ Boolean
- #message_update? ⇒ Boolean
- #name ⇒ Object
- #recipient ⇒ Object
- #recipient_mentioned? ⇒ Boolean
- #reply_to_id ⇒ Object
- #service_url ⇒ Object
-
#strip_mentions_text(account_id: nil, tag_only: false) ⇒ Object
Returns the text with "
... " mention tokens removed, without mutating the raw activity. - #suggested_action_submit? ⇒ Boolean
- #text ⇒ Object
- #to_h ⇒ Object
- #type ⇒ Object
- #typing? ⇒ Boolean
- #value ⇒ Object
Constructor Details
#initialize(raw = {}) ⇒ Activity
Returns a new instance of Activity.
7 8 9 |
# File 'lib/teams/activity.rb', line 7 def initialize(raw = {}) @raw = normalize_hash(raw) end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
5 6 7 |
# File 'lib/teams/activity.rb', line 5 def raw @raw end |
Instance Method Details
#channel_data ⇒ Object
47 48 49 |
# File 'lib/teams/activity.rb', line 47 def channel_data Api::ChannelData.new(raw["channelData"] || raw["channel_data"] || {}) end |
#channel_id ⇒ Object
35 36 37 |
# File 'lib/teams/activity.rb', line 35 def channel_id raw["channelId"] || raw["channel_id"] end |
#conversation ⇒ Object
59 60 61 |
# File 'lib/teams/activity.rb', line 59 def conversation Api::ConversationAccount.new(raw["conversation"] || {}) end |
#entities ⇒ Object
68 69 70 |
# File 'lib/teams/activity.rb', line 68 def entities Array(raw["entities"]) end |
#from ⇒ Object
51 52 53 |
# File 'lib/teams/activity.rb', line 51 def from Api::Account.new(raw["from"] || {}) end |
#get_account_mention(account_id) ⇒ Object
82 83 84 |
# File 'lib/teams/activity.rb', line 82 def get_account_mention(account_id) get_mentions.find { |mention| mention.dig("mentioned", "id") == account_id } end |
#get_mentions ⇒ Object
78 79 80 |
# File 'lib/teams/activity.rb', line 78 def get_mentions entities.select { |entity| entity.is_a?(Hash) && entity["type"] == "mention" } end |
#get_quoted_messages ⇒ Object
72 73 74 75 76 |
# File 'lib/teams/activity.rb', line 72 def entities .select { |entity| entity.is_a?(Hash) && entity["type"] == "quotedReply" } .map { |entity| Api::QuotedReplyEntity.new(entity) } end |
#id ⇒ Object
23 24 25 |
# File 'lib/teams/activity.rb', line 23 def id raw["id"] end |
#install_update? ⇒ Boolean
131 132 133 |
# File 'lib/teams/activity.rb', line 131 def install_update? type == "installationUpdate" end |
#invoke? ⇒ Boolean
127 128 129 |
# File 'lib/teams/activity.rb', line 127 def invoke? type == "invoke" end |
#local_timestamp ⇒ Object
43 44 45 |
# File 'lib/teams/activity.rb', line 43 def raw["localTimestamp"] || raw["local_timestamp"] end |
#locale ⇒ Object
39 40 41 |
# File 'lib/teams/activity.rb', line 39 def locale raw["locale"] end |
#message? ⇒ Boolean
115 116 117 |
# File 'lib/teams/activity.rb', line 115 def type == "message" end |
#message_update? ⇒ Boolean
119 120 121 |
# File 'lib/teams/activity.rb', line 119 def type == "messageUpdate" end |
#name ⇒ Object
15 16 17 |
# File 'lib/teams/activity.rb', line 15 def name raw["name"] end |
#recipient ⇒ Object
55 56 57 |
# File 'lib/teams/activity.rb', line 55 def recipient Api::Account.new(raw["recipient"] || {}) end |
#recipient_mentioned? ⇒ Boolean
86 87 88 |
# File 'lib/teams/activity.rb', line 86 def recipient_mentioned? !get_account_mention(recipient.id).nil? end |
#reply_to_id ⇒ Object
27 28 29 |
# File 'lib/teams/activity.rb', line 27 def reply_to_id raw["replyToId"] || raw["reply_to_id"] end |
#service_url ⇒ Object
31 32 33 |
# File 'lib/teams/activity.rb', line 31 def service_url raw["serviceUrl"] || raw["service_url"] end |
#strip_mentions_text(account_id: nil, tag_only: false) ⇒ Object
Returns the text with "
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/teams/activity.rb', line 93 def strip_mentions_text(account_id: nil, tag_only: false) return nil unless text get_mentions.reduce(text) do |result, mention| next result if account_id && mention.dig("mentioned", "id") != account_id mention_text = mention["text"].to_s if !mention_text.empty? = mention_text.gsub("<at>", "").gsub("</at>", "") result.sub(mention_text, tag_only ? : "") elsif (name = mention.dig("mentioned", "name")) result.sub("<at>#{name}</at>", tag_only ? name : "") else result end end.strip end |
#suggested_action_submit? ⇒ Boolean
135 136 137 |
# File 'lib/teams/activity.rb', line 135 def suggested_action_submit? type == "invoke" && name == "suggestedActions/submit" end |
#text ⇒ Object
19 20 21 |
# File 'lib/teams/activity.rb', line 19 def text raw["text"] end |
#to_h ⇒ Object
111 112 113 |
# File 'lib/teams/activity.rb', line 111 def to_h raw.dup end |
#type ⇒ Object
11 12 13 |
# File 'lib/teams/activity.rb', line 11 def type raw["type"] end |
#typing? ⇒ Boolean
123 124 125 |
# File 'lib/teams/activity.rb', line 123 def typing? type == "typing" end |
#value ⇒ Object
63 64 65 66 |
# File 'lib/teams/activity.rb', line 63 def value value = raw["value"] value.is_a?(Hash) ? Api::ActivityValue.new(value) : value end |