Class: Teams::Api::MessageActivity
- Inherits:
-
Object
- Object
- Teams::Api::MessageActivity
- Defined in:
- lib/teams/api/message_activity.rb
Constant Summary collapse
- TEXT_FORMATS =
%w[plain markdown xml extendedmarkdown].freeze
- FEEDBACK_MODES =
%w[default custom].freeze
- AI_MESSAGE_ENTITY_TYPE =
"https://schema.org/Message"
Instance Attribute Summary collapse
-
#attachments ⇒ Object
readonly
Returns the value of attribute attachments.
-
#channel_data ⇒ Object
readonly
Returns the value of attribute channel_data.
-
#entities ⇒ Object
readonly
Returns the value of attribute entities.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#input_hint ⇒ Object
readonly
Returns the value of attribute input_hint.
-
#recipient ⇒ Object
readonly
Returns the value of attribute recipient.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#text_format ⇒ Object
readonly
Returns the value of attribute text_format.
Instance Method Summary collapse
- #add_ai_generated ⇒ Object
- #add_card(card) ⇒ Object
- #add_citation(position, appearance) ⇒ Object
- #add_feedback(mode = "default") ⇒ Object
- #add_mention(account, text: nil, add_text: true) ⇒ Object
- #add_quote(message_id, text = nil) ⇒ Object
-
#add_sensitivity_label(name, description: nil, pattern: nil) ⇒ Object
Adds a content sensitivity label.
-
#add_targeted_message_info(message_id) ⇒ Object
Adds a targetedMessageInfo entity for prompt preview, once per message.
- #add_text(value) ⇒ Object
- #get_quoted_messages ⇒ Object
-
#initialize(text = nil, id: nil, attachments: [], text_format: nil, summary: nil, input_hint: nil) ⇒ MessageActivity
constructor
A new instance of MessageActivity.
- #prepend_quote(message_id) ⇒ Object
- #to_h ⇒ Object
- #with_id(id) ⇒ Object
- #with_recipient(account, is_targeted: nil) ⇒ Object
- #with_text_format(text_format) ⇒ Object
Constructor Details
#initialize(text = nil, id: nil, attachments: [], text_format: nil, summary: nil, input_hint: nil) ⇒ MessageActivity
Returns a new instance of MessageActivity.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/teams/api/message_activity.rb', line 12 def initialize(text = nil, id: nil, attachments: [], text_format: nil, summary: nil, input_hint: nil) @id = id @text = text @attachments = @text_format = normalize_text_format(text_format) @summary = summary @input_hint = input_hint @entities = [] @channel_data = {} @recipient = nil end |
Instance Attribute Details
#attachments ⇒ Object (readonly)
Returns the value of attribute attachments.
10 11 12 |
# File 'lib/teams/api/message_activity.rb', line 10 def @attachments end |
#channel_data ⇒ Object (readonly)
Returns the value of attribute channel_data.
10 11 12 |
# File 'lib/teams/api/message_activity.rb', line 10 def channel_data @channel_data end |
#entities ⇒ Object (readonly)
Returns the value of attribute entities.
10 11 12 |
# File 'lib/teams/api/message_activity.rb', line 10 def entities @entities end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/teams/api/message_activity.rb', line 10 def id @id end |
#input_hint ⇒ Object (readonly)
Returns the value of attribute input_hint.
10 11 12 |
# File 'lib/teams/api/message_activity.rb', line 10 def input_hint @input_hint end |
#recipient ⇒ Object (readonly)
Returns the value of attribute recipient.
10 11 12 |
# File 'lib/teams/api/message_activity.rb', line 10 def recipient @recipient end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
10 11 12 |
# File 'lib/teams/api/message_activity.rb', line 10 def summary @summary end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
10 11 12 |
# File 'lib/teams/api/message_activity.rb', line 10 def text @text end |
#text_format ⇒ Object (readonly)
Returns the value of attribute text_format.
10 11 12 |
# File 'lib/teams/api/message_activity.rb', line 10 def text_format @text_format end |
Instance Method Details
#add_ai_generated ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/teams/api/message_activity.rb', line 87 def add_ai_generated entity = additional_types = Array(entity["additionalType"]) return self if additional_types.include?("AIGeneratedContent") entity["additionalType"] = additional_types + ["AIGeneratedContent"] self end |
#add_card(card) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/teams/api/message_activity.rb', line 47 def add_card(card) @attachments << { "contentType" => "application/vnd.microsoft.card.adaptive", "content" => card.respond_to?(:to_h) ? card.to_h : card } self end |
#add_citation(position, appearance) ⇒ Object
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/teams/api/message_activity.rb', line 126 def add_citation(position, appearance) entity = entity["citation"] ||= [] entity["citation"] << { "@type" => "Claim", "position" => position, "appearance" => citation_appearance(appearance).to_h } self end |
#add_feedback(mode = "default") ⇒ Object
137 138 139 140 141 |
# File 'lib/teams/api/message_activity.rb', line 137 def add_feedback(mode = "default") @channel_data["feedbackLoop"] = { "type" => normalize_feedback_mode(mode) } @channel_data.delete("feedbackLoopEnabled") self end |
#add_mention(account, text: nil, add_text: true) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/teams/api/message_activity.rb', line 96 def add_mention(account, text: nil, add_text: true) account_hash = account.respond_to?(:to_h) ? account.to_h : account mention_text = text || account_hash["name"] self.add_text("<at>#{mention_text}</at>") if add_text @entities << { "type" => "mention", "mentioned" => account_hash, "text" => "<at>#{mention_text}</at>" } self end |
#add_quote(message_id, text = nil) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/teams/api/message_activity.rb', line 29 def add_quote(, text = nil) @entities << QuotedReplyEntity.new("quotedReply" => { "messageId" => }) add_text(%(<quoted messageId="#{}"/>)) add_text(" #{text}") if text self end |
#add_sensitivity_label(name, description: nil, pattern: nil) ⇒ Object
Adds a content sensitivity label. The label is carried as usageInfo on the root schema.org/Message entity, the wire shape TypeScript, Python, and the Teams documentation use.
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/teams/api/message_activity.rb', line 113 def add_sensitivity_label(name, description: nil, pattern: nil) usage_info = { "type" => AI_MESSAGE_ENTITY_TYPE, "@type" => "CreativeWork", "name" => name } usage_info["description"] = description if description usage_info["pattern"] = pattern if pattern ["usageInfo"] = usage_info self end |
#add_targeted_message_info(message_id) ⇒ Object
Adds a targetedMessageInfo entity for prompt preview, once per message. Any quotedReply entities and the matching quote placeholder are removed to avoid collision with the prompt preview.
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/teams/api/message_activity.rb', line 76 def () @entities.reject! { |entity| quoted_reply_entity?(entity) } @text = text.gsub(%(<quoted messageId="#{}"/>), "").strip if text unless @entities.any? { |entity| entity_type(entity) == "targetedMessageInfo" } @entities << { "type" => "targetedMessageInfo", "messageId" => } end self end |
#add_text(value) ⇒ Object
24 25 26 27 |
# File 'lib/teams/api/message_activity.rb', line 24 def add_text(value) @text = "#{text}#{value}" self end |
#get_quoted_messages ⇒ Object
43 44 45 |
# File 'lib/teams/api/message_activity.rb', line 43 def entities.select { |entity| quoted_reply_entity?(entity) } end |
#prepend_quote(message_id) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/teams/api/message_activity.rb', line 36 def prepend_quote() @entities << QuotedReplyEntity.new("quotedReply" => { "messageId" => }) placeholder = %(<quoted messageId="#{}"/>) @text = text.to_s.strip.empty? ? placeholder : "#{placeholder} #{text}" self end |
#to_h ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/teams/api/message_activity.rb', line 143 def to_h body = { "type" => "message" } body["id"] = id if id body["text"] = text if text body["textFormat"] = text_format if text_format body["summary"] = summary if summary body["inputHint"] = input_hint if input_hint body["attachments"] = unless .empty? body["entities"] = @entities.map { |entity| entity.respond_to?(:to_h) ? entity.to_h : entity } unless @entities.empty? body["channelData"] = channel_data unless channel_data.empty? body["recipient"] = recipient if recipient body end |
#with_id(id) ⇒ Object
60 61 62 63 |
# File 'lib/teams/api/message_activity.rb', line 60 def with_id(id) @id = id self end |
#with_recipient(account, is_targeted: nil) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/teams/api/message_activity.rb', line 65 def with_recipient(account, is_targeted: nil) body = account.respond_to?(:to_h) ? account.to_h : account body = body.dup body["isTargeted"] = is_targeted unless is_targeted.nil? @recipient = body self end |
#with_text_format(text_format) ⇒ Object
55 56 57 58 |
# File 'lib/teams/api/message_activity.rb', line 55 def with_text_format(text_format) @text_format = normalize_text_format(text_format) self end |