Created
December 7, 2020 10:28
-
-
Save asdqwe3124/ec84303241f49a6f3164721508460457 to your computer and use it in GitHub Desktop.
mock-smtp-server.js
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
const SMTPServer = require("smtp-server").SMTPServer; | |
const TelegramBot = require('node-telegram-bot-api'); | |
const fetch = require('node-fetch'); | |
const TelegramToken = ''; | |
const bot = new TelegramBot(TelegramToken, {polling: false}); | |
const chatId = ''; | |
const server = new SMTPServer({ | |
onConnect(session, callback) { | |
// if (session.remoteAddress === "10.10.10.2") { | |
// return callback(new Error("No connections from localhost allowed")); | |
// } | |
console.log("Motion Detected"); | |
bot.sendMessage(chatId, 'Motion Detected'); | |
let url = 'http://IP-CAMERA-IP-ADDRESS/webcapture.jpg?user=USERNAME&password=PASSWORD&command=snap&channel=1'; | |
fetch(url).then((res) => res.buffer()).then(buffer => bot.sendPhoto(chatId, buffer)); | |
return callback(); // Accept the connection | |
} | |
}); | |
server.on("error", err => { | |
console.log("Error %s", err.message); | |
}); | |
server.listen(25); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment