-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 3231/add mention functionality (#4)
* [lib/msteams_hermes/msteams/entities/*.rb]: Add classes to support mentions * [adaptive_card.rb]: Add support for entities which encapsulate the mention type https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format?tabs=adaptive-md%2Cdesktop%2Cconnector-html#mention-support-within-adaptive-cards * [lib/msteams_hermes/components/base.rb]: Remove superfluous 'require' * [mention.rb]: Remove accessors They aren't used as of now * [lib/msteams_hermes/msteams/entities/mention.rb]: Add guard exceptions * mention_spec.rb]: Add rspec test for mention class * [lib/msteams_hermes/components/adaptive_card.rb]: Formatting change * [adaptive_card_spec.rb]: Incorporate entities key that comes with supporting mentions * [message_spec.rb]: Adapt test to accomodate 'msteams' and 'entities' key Necessary to support mentions * [lib/msteams_hermes/msteams/entities/base.rb]: Address rubocop issue * [entities/mention.rb]: Address rubocop issue * [lib/msteams_hermes/msteams/entities/mention.rb]: Address rubocop issue * [entities/mention.rb]: Maybe this change for 2.7 rubocopping? * Update lib/msteams_hermes/msteams/entities/mention.rb Co-authored-by: Rafael Rocha <[email protected]> * Update lib/msteams_hermes/msteams/entities/mention.rb Co-authored-by: Rafael Rocha <[email protected]> * [mention_spec.rb]: Add rspec test of 'to_hash' * Update lib/msteams_hermes/components/adaptive_card.rb Co-authored-by: Jason Franklin <[email protected]> * Update lib/msteams_hermes/components/adaptive_card.rb Co-authored-by: Jason Franklin <[email protected]> * Update lib/msteams_hermes/msteams/entities/mention.rb Co-authored-by: Jason Franklin <[email protected]> * Revert "Update lib/msteams_hermes/msteams/entities/mention.rb" This reverts commit 168e105. The parameters of the mention class should not be optional * [adaptive_card_spec.rb]: Adapt tests to comply with ea70fb * [spec/msteams_hermes/entities/mention_spec.rb]: Rubocopping Co-authored-by: Rafael Rocha <[email protected]> Co-authored-by: Jason Franklin <[email protected]>
- Loading branch information
1 parent
9eb5923
commit 2a7e13d
Showing
7 changed files
with
103 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module MsTeamsHermes | ||
module MsTeams | ||
module Entities | ||
# Super class for entities to enforce overridding the `to_hash` method | ||
class Base | ||
def to_hash | ||
raise "Should be implemented on the subclass" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
require "msteams_hermes/msteams/entities/base" | ||
|
||
module MsTeamsHermes | ||
module MsTeams | ||
module Entities | ||
## | ||
# A class representing Microsoft's Msteams.Mention object | ||
# https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format?tabs=adaptive-md%2Cdesktop%2Cconnector-html#user-mention-in-incoming-webhook-with-adaptive-cards | ||
## | ||
class Mention < Base | ||
attr_reader :mention_reference, :mention_string, :user_id | ||
|
||
def initialize(text:, name:, id:) | ||
raise "`text` must be a string" unless text.is_a? String | ||
raise "`text` must contain <at>...</at>" unless text.include?("<at>") && text.include?("</at>") | ||
raise "`id` must be a string" unless text.is_a? String | ||
|
||
@mention_reference = text # String surrounded by <at>string</at> that marks the mention section in a text | ||
@mention_string = name # allows for overriding the mention_reference | ||
@user_id = id | ||
end | ||
|
||
def to_hash | ||
{ | ||
type: "mention", | ||
text: mention_reference, | ||
mentioned: { | ||
id: user_id, | ||
name: mention_string | ||
} | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,8 @@ | |
title: nil, | ||
tooltip: nil | ||
} | ||
] | ||
], | ||
msteams: { entities: [] } | ||
} | ||
|
||
expect(component.to_hash).to eq hash | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
require "msteams_hermes/msteams/entities/mention" | ||
|
||
RSpec.describe MsTeamsHermes::MsTeams::Entities::Mention do | ||
describe "#initialize" do | ||
it "throws an error if text parameter does not contain <at> and </at>" do | ||
expect do | ||
MsTeamsHermes::MsTeams::Entities::Mention.new(text: "foo", name: "something", id: "123") | ||
end.to raise_error("`text` must contain <at>...</at>") | ||
end | ||
end | ||
|
||
describe "#to_hash" do | ||
subject(:mention) do | ||
MsTeamsHermes::MsTeams::Entities::Mention.new(text: mention_segment_in_text, | ||
name: mention_string, | ||
id: user_id) | ||
end | ||
|
||
let(:mention_segment_in_text) { "<at>original text reference</at>" } | ||
let(:user_id) { "[email protected]" } | ||
let(:mention_string) { "Text to show up as mention" } | ||
|
||
it "renders the hash object" do | ||
expected_hash = { | ||
type: "mention", | ||
text: mention_segment_in_text, | ||
mentioned: { | ||
id: user_id, | ||
name: mention_string | ||
} | ||
} | ||
|
||
expect(mention.to_hash).to eq(expected_hash) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,10 @@ | |
facts: [fact] | ||
} | ||
], | ||
actions: nil | ||
actions: nil, | ||
msteams: { | ||
entities: [] | ||
} | ||
} | ||
} | ||
] | ||
|