-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any interest in extending the MessageCard type? #6
Comments
@atc0005 I tried to compare draft 1 and 2. some thoughts:
Would you like to start with a branch? (It looks better for me when you are the contributor ...) |
Thanks, I was hoping so. The first draft was nearly 1:1 from the output generated by https://mholt.github.io/json-to-go/, which was a great starting point (IMHO) since I'm not yet familiar enough to craft a Go struct equivalent from JSON objects. I also tried to trim back fields that didn't appear strictly necessary with the thoughts that they could be added in a later revision if needed.
Mostly scope. Before I checked with you to see if you had interest in incorporating the changes here, I decided I would press forward either way with implementing changes that I need for another project (which uses this package). I knew that my Go skills are still very limited (I consider myself still very new to the language), so I didn't want to try and implement too much, too early if I couldn't find away to do it properly.
From my initial, limited testing I came to the same conclusion. The additional fields allowed for further expansion of functionality without breaking any existing code that only used the initial three fields. |
I can. How quickly are you looking to move forward with this? I've started hacking together some large changes to test a few ideas on my fork and was planning on cleaning things up before presenting here. A few changes from the fork worth sharing now:
Example methods (and just signature for the last one): func (mc *MessageCard) AddSection(section ...MessageCardSection) {
mc.Sections = append(mc.Sections, section...)
}
// AddFact adds one or many additional MessageCardSectionFact values to a
// MessageCardSection
func (mcs *MessageCardSection) AddFact(fact ...MessageCardSectionFact) {
mcs.Facts = append(mcs.Facts, fact...)
}
// AddFactFromKeyValue accepts a key and slice of values and converts them to
// MessageCardSectionFact values
func (mcs *MessageCardSection) AddFactFromKeyValue(key string, values ...string) error {
...
}
This may be some other changes, but this is what I spotted when doing a quick review to gather notes for posting here. |
In case my uses cases are too vague, here is an example of the output generated by a small webhook payload testing app: and here is a screenshot showing the received message generated by a small CLI app I wrote (and am heavily refactoring) which uses a fork of this project: That fork contains the changes I mentioned in my last post. I'm hoping to cleanup those changes and break into specific change sets. I'd then use those sets with Pull Requests for potential inclusion here. |
Back to your notes here:
If you want, I can spin off a branch to include the type changes noted in the OP (going with a draft 3 that brings back Which branch should I file a Pull Request against? I assume |
Follow-up: I still feel that the idea fits, but the current implementation has a bug (just in case you look at them) that I'm working through. EDIT: It was a bug elsewhere, the methods appear to work as intended. |
Worth noting (scratch notes from this morning's pre-work dev time): The |
The more I dig into this, the more I keep returning to the idea that support for https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#actions As noted previously, 5 different types are supported (with one of them presumably deprecated since it's not listed) and each type of |
It is indeed deprecated:
refs https://stackoverflow.com/a/44061405 EDIT: Also mentioned here:
That note is relevant, but potentially confusing though, as there are five types with only four being relevant to Microsoft Teams:
|
The branch "v2" will be removed soon. The branch master represent now "v2..". This should be the branch to setup a pull request against.
Agree. It's always a better idea to keep the changes small. |
Acknowledged. I'll try to get something together over the next day or so. As mentioned previously I've made a number of changes as part of testing integration with a few projects of mine. How small would you like the Pull Requests? I can go with just the type changes or type changes + associated methods. There are other changes that I'm not even sure are a solid fit, so I wouldn't want to include those just yet, though they would likely show up in a draft PR not long behind to aid in further discussions.
Sounds good to me. I fought with it for a while before I realized I wasn't ready yet to take it on. I'm still giving it some thought, so maybe after the other changes land and stabilize we can look further into it. |
NEW: - `MessageCard` type includes additional fields - `Type` and `Context` fields provide required JSON payload fields - preset to required static values via updated `NewMessageCard()` constructor - `Summary` - required if `Text` field is not set, optional otherwise - `Sections` slice - `MessageCardSection` type - Additional nested types - `MessageCardSection` - `MessageCardSectionFact` - `MessageCardSectionImage` - Additional methods for `MessageCard` and nested types - `MessageCard.AddSection()` - `MessageCardSection.AddFact()` - `MessageCardSection.AddFactFromKeyValue()` - `MessageCardSection.AddImage()` - `MessageCardSection.AddHeroImageStr()` - `MessageCardSection.AddHeroImage()` - Additional factory functions - `NewMessageCardSection()` - `NewMessageCardSectionFact()` - `NewMessageCardSectionImage()` - `IsValidMessageCard` added to check for minimum required field values. - This function has the potential to be extended later with additional validation steps. CHANGED: - `MessageCard` type includes additional fields - `NewMessageCard` factory function sets fields needed for required JSON payload fields - `Type` - `Context` - `teamsClient.Send()` method updated to apply `MessageCard` struct validation alongside existing webhook URL validation - `isValidWebhookURL` exported as `IsValidWebhookURL` so that client code can use the validation functionality instead of repeating the code - e.g., flag value validation for "fail early" behavior KNOWN ISSUES: - No support in this set of changes for `potentialAction` types - `ViewAction` - `OpenUri` - `HttpPOST` - `ActionCard` - `InvokeAddInCommand` - Outlook specific based on what I read; likely not included in a future release due to non-Teams specific usage refs dasrick#6
NEW: - `MessageCard` type includes additional fields - `Type` and `Context` fields provide required JSON payload fields - preset to required static values via updated `NewMessageCard()` constructor - `Summary` - required if `Text` field is not set, optional otherwise - `Sections` slice - `MessageCardSection` type - Additional nested types - `MessageCardSection` - `MessageCardSectionFact` - `MessageCardSectionImage` - Additional methods for `MessageCard` and nested types - `MessageCard.AddSection()` - `MessageCardSection.AddFact()` - `MessageCardSection.AddFactFromKeyValue()` - `MessageCardSection.AddImage()` - `MessageCardSection.AddHeroImageStr()` - `MessageCardSection.AddHeroImage()` - Additional factory functions - `NewMessageCardSection()` - `NewMessageCardSectionFact()` - `NewMessageCardSectionImage()` - `IsValidMessageCard()` added to check for minimum required field values. - This function has the potential to be extended later with additional validation steps. CHANGED: - `MessageCard` type includes additional fields - `NewMessageCard` factory function sets fields needed for required JSON payload fields - `Type` - `Context` - `teamsClient.Send()` method updated to apply `MessageCard` struct validation alongside existing webhook URL validation - `isValidWebhookURL()` exported as `IsValidWebhookURL()` so that client code can use the validation functionality instead of repeating the code - e.g., flag value validation for "fail early" behavior KNOWN ISSUES: - No support in this set of changes for `potentialAction` types - `ViewAction` - `OpenUri` - `HttpPOST` - `ActionCard` - `InvokeAddInCommand` - Outlook specific based on what I read; likely not included in a future release due to non-Teams specific usage refs dasrick#6
NEW: - `MessageCard` type includes additional fields - `Type` and `Context` fields provide required JSON payload fields - preset to required static values via updated `NewMessageCard()` constructor - `Summary` - required if `Text` field is not set, optional otherwise - `Sections` slice - `MessageCardSection` type - Additional nested types - `MessageCardSection` - `MessageCardSectionFact` - `MessageCardSectionImage` - Additional methods for `MessageCard` and nested types - `MessageCard.AddSection()` - `MessageCardSection.AddFact()` - `MessageCardSection.AddFactFromKeyValue()` - `MessageCardSection.AddImage()` - `MessageCardSection.AddHeroImageStr()` - `MessageCardSection.AddHeroImage()` - Additional factory functions - `NewMessageCardSection()` - `NewMessageCardSectionFact()` - `NewMessageCardSectionImage()` - `IsValidMessageCard()` added to check for minimum required field values. - This function has the potential to be extended later with additional validation steps. CHANGED: - `MessageCard` type includes additional fields - `NewMessageCard` factory function sets fields needed for required JSON payload fields - `Type` - `Context` - `teamsClient.Send()` method updated to apply `MessageCard` struct validation alongside existing webhook URL validation - `isValidWebhookURL()` exported as `IsValidWebhookURL()` so that client code can use the validation functionality instead of repeating the code - e.g., flag value validation for "fail early" behavior KNOWN ISSUES: - No support in this set of changes for `potentialAction` types - `ViewAction` - `OpenUri` - `HttpPOST` - `ActionCard` - `InvokeAddInCommand` - Outlook specific based on what I read; likely not included in a future release due to non-Teams specific usage refs dasrick#6
NEW: - `MessageCard` type includes additional fields - `Type` and `Context` fields provide required JSON payload fields - preset to required static values via updated `NewMessageCard()` constructor - `Summary` - required if `Text` field is not set, optional otherwise - `Sections` slice - `MessageCardSection` type - Additional nested types - `MessageCardSection` - `MessageCardSectionFact` - `MessageCardSectionImage` - Additional methods for `MessageCard` and nested types - `MessageCard.AddSection()` - `MessageCardSection.AddFact()` - `MessageCardSection.AddFactFromKeyValue()` - `MessageCardSection.AddImage()` - `MessageCardSection.AddHeroImageStr()` - `MessageCardSection.AddHeroImage()` - Additional factory functions - `NewMessageCardSection()` - `NewMessageCardSectionFact()` - `NewMessageCardSectionImage()` - `IsValidMessageCard()` added to check for minimum required field values. - This function has the potential to be extended later with additional validation steps. - Wrapper `IsValidInput()` added to handle all validation needs from one location. - the intent was to both solve a CI erro and provide a location to easily extend validation checks in the future (if needed) CHANGED: - `MessageCard` type includes additional fields - `NewMessageCard` factory function sets fields needed for required JSON payload fields - `Type` - `Context` - `teamsClient.Send()` method updated to apply `MessageCard` struct validation alongside existing webhook URL validation - `isValidWebhookURL()` exported as `IsValidWebhookURL()` so that client code can use the validation functionality instead of repeating the code - e.g., flag value validation for "fail early" behavior KNOWN ISSUES: - No support in this set of changes for `potentialAction` types - `ViewAction` - `OpenUri` - `HttpPOST` - `ActionCard` - `InvokeAddInCommand` - Outlook specific based on what I read; likely not included in a future release due to non-Teams specific usage refs dasrick#6
I added some review comments on #12; noting that here in case those remarks get lost in other repo notification traffic. On that PR I asked about the scopelint linter warning that my changes generated. I'll go ahead and submit another PR (referencing this issue) to make it easier to discuss that specifically. |
Error from `scopelint` linter: "Using a reference for the variable on range scope `img`" Fix: Use index from range loop to *reach into* the slice argument to retrieve the address of those values instead of using the range loop variable, which likely would have been a subtle source of bugs later on. refs #6, #11, #12
Error from `scopelint` linter: "Using a reference for the variable on range scope `img`" Fix: Use index from range loop to *reach into* the slice argument to retrieve the address of those values instead of using the range loop variable, which likely would have been a subtle source of bugs later on. refs #6, #11, #12
Error from `scopelint` linter: "Using a reference for the variable on range scope `img`" Fix: Use index from range loop to *reach into* the slice argument to retrieve the address of those values instead of using the range loop variable, which likely would have been a subtle source of bugs later on. refs #6, #11, #12
Error from `scopelint` linter: "Using a reference for the variable on range scope `img`" Fix: Use index from range loop to *reach into* the slice argument to retrieve the address of those values instead of using the range loop variable, which likely would have been a subtle source of bugs later on. refs #6, #11, #12
Extend error handling by retrieving and providing the response string from the remote API as part of the error message returned to the caller if the status code indicates an error condition. Based on testing, the response string contains useful troubleshooting information which can help identify missing information in the submitted MessageCard payload. --- Note: This commit contains example `logger` object calls to illustrate the proposed changes mentioned in #10. Before the associated PR would be merged, those `logger` calls would be removed and implemented as part of a separate PR specific to #10. refs #10, #6 (loosely)
- Convert Windows/Mac/Linux EOL to Markdown break statements - used to provide equivalent Teams-compatible formatting - Format text as code snippet - this inserts leading and trailing ` character to provide Markdown string formatting - Format text as code block - this inserts three leading and trailing ` characters to provide Markdown code block formatting - `Try` variants of code formatting functions - return formatted string if no errors, otherwise return the original string refs #6 (loosely)
- Move webhook URL prefixes to constants list - export so that client code may reference them with any validation work that they perform - Collect and return user-provided webhook URL alongside required URL prefixes to help aid with troubleshooting the cause of any errors that they may receive refs #6 (loosely)
This was intended to go in with the other work for dasrick#6, but I think this assignment statement was unintentionaly trimmed alongside the removal of the package-level logger statements referenced in dasrick#10. I caught this when performing a test rebase to audit what remaining changes in my fork haven't been included or proposed in the parent/upstream project.
This was intended to go in with the other work for dasrick#6, but I think this assignment statement was unintentionally trimmed alongside the removal of the package-level logger statements referenced in dasrick#10. I caught this when performing a test rebase to audit what remaining changes in my fork haven't been included or proposed in the parent/upstream project.
Overview
I'm working on several small projects where I'm looking to use this package for submitting notifications to Microsoft Teams. As part of that work, I plan on including JSON data and some verbose client details.
To that end I'm looking at using
sections
with multiplefacts
entries, but I'm not sure yet of the final payload details.Example JSON
Example, stripped down copy of the JSON content that I'm toying with:
Required fields
FWIW, the reference guide says that these two fields are required, but from testing it appears that Teams is pretty lenient about leaving them out:
Draft 1 changes
The struct changes were generated by running the sample JSON through https://mholt.github.io/json-to-go/ and then tweaking the output to add additional
omitifempty
qualifiers. I have only just begun testing using the changes, so I can't speak to the accuracy of the results.I don't know if this is the right way to do it, but I modified the constructor function to handle presetting the required fields since they're static values. While Teams is happy to accept payloads without those fields, since their docs note they're required it seems like good future-proofing to go ahead and include them.
Draft 2 changes
Stripped out all comments in the above to save space. There may be other fields to add/remove to suit more general needs. No changes to the
NewMessageCard()
constructor since Draft 1.References
go-teams-notify/send.go
Lines 64 to 69 in feea812
The text was updated successfully, but these errors were encountered: