-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from 4urcloud/dev-esteban-reworkTeamsNotification
reworked all teams notifications
- Loading branch information
Showing
8 changed files
with
445 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const levelAlert = ["info", "warning", "error", "fatal"]; | ||
export const Teams = { | ||
//https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using?tabs=cURL | ||
OneTeams: (color:string, subject:string, url:string, description:string) => { | ||
return JSON.stringify({ | ||
"@type": "MessageCard", | ||
"@context": "http://schema.org/extensions", | ||
"themeColor": color, | ||
"summary": subject, | ||
"sections": [ | ||
{ | ||
"activityTitle": subject, | ||
"activitySubtitle": description, | ||
"activityImage": "https://kexa.io/kexa-no-background-color.png", | ||
"markdown": true | ||
} | ||
], | ||
"potentialAction": [ | ||
{ | ||
"@type": "OpenUri", | ||
"name": "Go to ressource", | ||
"targets": [ | ||
{ | ||
"os": "default", | ||
"uri": url | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
}, | ||
GlobalTeams: (color:string, subject:string, text:string, errors:{ [x: string]: number; }) => { | ||
return JSON.stringify({ | ||
"@type": "MessageCard", | ||
"@context": "http://schema.org/extensions", | ||
"themeColor": color, | ||
"summary": subject, | ||
"sections": [ | ||
{ | ||
"activityTitle": subject, | ||
"activitySubtitle": "Kexa by 4urcloud", | ||
"activityImage": "https://kexa.io/kexa-no-background-color.png", | ||
"text": text, | ||
"facts": Object.entries(errors).map(([name, value]) => { | ||
return { | ||
"name": name, | ||
"value": value.toString() | ||
}; | ||
}), | ||
"markdown": true | ||
} | ||
] | ||
}); | ||
}, | ||
}; |
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,34 @@ | ||
const jsdom = require("jsdom") | ||
const { JSDOM } = jsdom | ||
global.DOMParser = new JSDOM().window.DOMParser | ||
|
||
export const extractURL = (text: string): string | null => { | ||
return extractFirstURLFromHTML(text)??extractFirstURL(text); | ||
} | ||
|
||
function extractFirstURLFromHTML(html: string): string | null { | ||
const parser = new DOMParser(); | ||
const doc = parser.parseFromString(html, 'text/html'); | ||
|
||
const urlElements = Array.from(doc.querySelectorAll('a[href], img[src]')); | ||
|
||
for (const element of urlElements) { | ||
const url = (element as HTMLAnchorElement).href || (element as HTMLImageElement).src; | ||
if (url) { | ||
return url; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
function extractFirstURL(input:string): string | null { | ||
const urlRegex = /(https?:\/\/[^\s]+)/g; | ||
const matches = input.match(urlRegex); | ||
|
||
if (matches && matches.length > 0) { | ||
return matches[0]; | ||
} | ||
|
||
return null; | ||
} |
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,21 @@ | ||
export const splitProperty = (prop: string, delimiter:string, ignore:string="/"):string[] => { | ||
const result = []; | ||
let current = ""; | ||
let escape = false; | ||
|
||
for (const char of prop) { | ||
if (char === delimiter && !escape) { | ||
result.push(current); | ||
current = ""; | ||
} else if (char === ignore && !escape) { | ||
escape = true; | ||
} else { | ||
if(escape && char !== delimiter) current += ignore; | ||
current += char; | ||
escape = false; | ||
} | ||
} | ||
|
||
result.push(current); | ||
return result; | ||
} |
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
Oops, something went wrong.