Skip to content

Instantly share code, notes, and snippets.

@OsvaldoFrias
Created October 26, 2022 22:14
Show Gist options
  • Save OsvaldoFrias/e8bccdbe99fc826c2e3fa24e48212e8c to your computer and use it in GitHub Desktop.
Save OsvaldoFrias/e8bccdbe99fc826c2e3fa24e48212e8c to your computer and use it in GitHub Desktop.
const BOT_TOKEN = '';
const BOT_GROUP = 0;
const URL_BASE = 'http://10.0.1.12:21093';
const securos = require('securos');
const http = require('http');
const { Telegraf } = require('telegraf');
const bot = new Telegraf(BOT_TOKEN);
// bot.telegram.sendMessage(BOT_GROUP, 'Bienvenido al Bot de reconocimiento facial de SecurOS FaceX.', {});
securos.connect(async (core) => {
core.registerEventHandler("FACE_X_SERVER", "*", "MATCH", sendNotification);
async function sendNotification(eventData) {
try {
const owner = eventData["params"]["owner"];
const comment = JSON.parse(eventData["params"]["comment"]);
if (comment["list"]["priority"] !== 0) return;
// console.log(eventData);
const faceImage = comment["_links"]["detection_image"];
const matchedFaceImage = comment['matched_person_face_image']['_links']['source'];
const personFound = comment["person"];
let personData = `👤 ${personFound.first_name || ''} ${personFound.middle_name || ''} ${personFound.last_name || ''}`;
let listData = `${personFound.lists.reduce((previousValue, currentValue) => {
let priority = currentValue.priority === 0 ? `🟥` : currentValue.priority === 1 ? `🟦` : `✅`;
return previousValue + `${priority} - ${currentValue.name}` + '\n';
}, '\n')}`;
bot.telegram.sendPhoto(BOT_GROUP,
{ source: await getStreamFromUrlHttp(`http://${owner}:21093${faceImage}`) },
{ caption: "Persona capturada" }
);
bot.telegram.sendPhoto(BOT_GROUP,
{ source: await getStreamFromUrlHttp(`${URL_BASE}${matchedFaceImage}`) },
//{ source: await getStreamFromUrlHttp(`http://${slaveId}:21093${matchedFaceImage}`) },
{ caption: "Persona encontrada" + '\n' + personData + listData }
);
// bot.telegram.sendMessage(BOT_GROUP, 'Bienvenido al Bot de reconocimiento facial de SecurOS FaceX.', {});
} catch (ex) {
console.error(ex);
}
}
});
// bot.start(async (ctx) => {
// console.log(ctx.update.message.chat);
// ctx.reply('Bienvenido al Bot de reconocimiento facial de SecurOS FaceX.');
// });
// bot.launch();
function getStreamFromUrlHttp(url) {
console.log(url);
return new Promise((resolve, reject) => {
try {
http.get(url, (stream) => {
resolve(stream);
});
} catch (ex) {
console.error(ex);
reject(ex);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment