teams-webhook-notifier
Version:
Notificador simples via Microsoft Teams Webhook com suporte a observabilidade.
44 lines (41 loc) • 1.24 kB
JavaScript
// src/infra/services/microsoft.service.ts
import axios from "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 axios.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)}`);
}
}
};
export {
MicrosoftService
};