Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var TelegramBot = require('node-telegram-bot-api');
- var exec = require('child_process').exec;
- var BOT_TOKEN = '.';
- var bot = new TelegramBot(BOT_TOKEN, {polling: true});
- var photoQueue = [];
- bot.onText(/\/photo/, function (msg) {
- console.log('photo');
- photoQueue.push(msg);
- takeAndSendPhoto(photoQueue[photoQueue.length - 1]);
- });
- function takeAndSendPhoto(msg) {
- bot.sendChatAction(msg.chat.id, 'upload_photo').then(function() {
- console.log('take photo');
- exec('raspistill -o /home/pi/pi-camera-bot/temp.jpg ', function photoTaken() {
- bot.sendPhoto(msg.chat.id, '/home/pi/pi-camera-bot/temp.jpg', {caption: new Date().toLocaleString()}).then(function nextPhoto() {
- photoQueue.pop();
- if (photoQueue.length > 0) {
- takeAndSendPhoto(photoQueue[photoQueue.length - 1]);
- }
- });
- })});
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement