Class: Teams::Api::MessageActivity
- Inherits:
-
Object
- Object
- Teams::Api::MessageActivity
- Defined in:
- lib/teams/api/message_activity.rb
Constant Summary collapse
- TEXT_FORMATS =
"extendedmarkdown" is in public preview and may be subject to change.
%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.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/teams/api/message_activity.rb', line 13 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.
11 12 13 |
# File 'lib/teams/api/message_activity.rb', line 11 def @attachments end |
#channel_data ⇒ Object (readonly)
Returns the value of attribute channel_data.
11 12 13 |
# File 'lib/teams/api/message_activity.rb', line 11 def channel_data @channel_data end |
#entities ⇒ Object (readonly)
Returns the value of attribute entities.
11 12 13 |
# File 'lib/teams/api/message_activity.rb', line 11 def entities @entities end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/teams/api/message_activity.rb', line 11 def id @id end |
#input_hint ⇒ Object (readonly)
Returns the value of attribute input_hint.
11 12 13 |
# File 'lib/teams/api/message_activity.rb', line 11 def input_hint @input_hint end |
#recipient ⇒ Object (readonly)
Returns the value of attribute recipient.
11 12 13 |
# File 'lib/teams/api/message_activity.rb', line 11 def recipient @recipient end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
11 12 13 |
# File 'lib/teams/api/message_activity.rb', line 11 def summary @summary end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
11 12 13 |
# File 'lib/teams/api/message_activity.rb', line 11 def text @text end |
#text_format ⇒ Object (readonly)
Returns the value of attribute text_format.
11 12 13 |
# File 'lib/teams/api/message_activity.rb', line 11 def text_format @text_format end |
Instance Method Details
#add_ai_generated ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/teams/api/message_activity.rb', line 88 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
48 49 50 51 52 53 54 |
# File 'lib/teams/api/message_activity.rb', line 48 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
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/teams/api/message_activity.rb', line 127 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
138 139 140 141 142 |
# File 'lib/teams/api/message_activity.rb', line 138 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
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/teams/api/message_activity.rb', line 97 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
30 31 32 33 34 35 |
# File 'lib/teams/api/message_activity.rb', line 30 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.
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/teams/api/message_activity.rb', line 114 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.
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/teams/api/message_activity.rb', line 77 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
25 26 27 28 |
# File 'lib/teams/api/message_activity.rb', line 25 def add_text(value) @text = "#{text}#{value}" self end |
#get_quoted_messages ⇒ Object
44 45 46 |
# File 'lib/teams/api/message_activity.rb', line 44 def entities.select { |entity| quoted_reply_entity?(entity) } end |
#prepend_quote(message_id) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/teams/api/message_activity.rb', line 37 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
144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/teams/api/message_activity.rb', line 144 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
61 62 63 64 |
# File 'lib/teams/api/message_activity.rb', line 61 def with_id(id) @id = id self end |
#with_recipient(account, is_targeted: nil) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/teams/api/message_activity.rb', line 66 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
56 57 58 59 |
# File 'lib/teams/api/message_activity.rb', line 56 def with_text_format(text_format) @text_format = normalize_text_format(text_format) self end |