teams-webhook-notifier
Version:
Notificador simples via Microsoft Teams Webhook com suporte a observabilidade.
81 lines (76 loc) • 2.91 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
MicrosoftService: () => MicrosoftService
});
module.exports = __toCommonJS(index_exports);
// src/infra/services/microsoft.service.ts
var import_axios = __toESM(require("axios"));
// src/shared/utils/logger.ts
var log = (message) => {
const timestamp = new Intl.DateTimeFormat("pt-BR", {
timeZone: "America/Sao_Paulo",
hour12: false,
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit"
}).format(/* @__PURE__ */ new Date());
console.log(`[${timestamp}] ${message}`);
};
// src/infra/services/microsoft.service.ts
var MicrosoftService = class {
constructor(webhookUrl) {
this.webhookUrl = webhookUrl;
}
async sendMessage(title = "\u{1F5A5}\uFE0F Projeto XXX", text) {
try {
const payload = {
"@type": "MessageCard",
"@context": "https://schema.org/extensions",
summary: `${title} - Nova mensagem`,
themeColor: "0076D7",
title,
sections: [{ text }]
};
const response = await import_axios.default.post(this.webhookUrl, payload, { headers: { "Content-Type": "application/json" } });
if (response.status === 200) log("\u{1F7E2} Mensagem enviada com sucesso!");
} catch (error) {
log(`\u{1F534} Erro ao enviar mensagem: ${String(error)}`);
}
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MicrosoftService
});