"use strict";
const nodemailer = require("nodemailer");
let testAccount = nodemailer.createTestAccount();
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'central_email_address',
pass: 'central_email_address_password'
}
});
var mqtt = require('mqtt');
var hostname = "mqtt://raspberrypi.local"; // put in ip address of raspberry pi
var client = mqtt.connect(hostname);
client.on('connect', function () {
console.log("[Snips Log] Connected to MQTT broker " + hostname);
client.subscribe('hermes/#');
});
client.on('message', function (topic, message) {
if (topic === "hermes/asr/startListening") {
onListeningStateChanged(true);
} else if (topic === "hermes/asr/stopListening") {
onListeningStateChanged(false);
} else if (topic.match(/hermes\/hotword\/.+\/detected/g) !== null) {
onHotwordDetected()
} else if (topic.match(/hermes\/intent\/.+/g) !== null) {
onIntentDetected(JSON.parse(message));
}
});
function onIntentDetected(intent) {
console.log("[Snips Log] Intent detected: " + JSON.stringify(intent));
var roommate_array = ["roommate_1", "roommate_2", "roommate_3"];
var roommate_email = ["email_1", "email_2", "email_3"];
var chore_array = ["chore_1", "chore_2", "chore_3", "chore_4"];
var roommate;
var chore;
for(roommate = 0; roommate < roommate_array.length; roommate++)
{
if(intent.search(roommate_array[roommate]) != -1)
{
for(chore = 0; chore < chore_array.length; chore++)
{
if(intent.search(chore_array[chore]) != -1)
{
break;
}
}
break;
}
}
//console.log(intent);
let info = transporter.sendMail({
from: '<central_email_address>', // central address you have to replace this
to: roommate_email[roommate],// roommate to contact
subject: chore_array[chore] // chore to do
});
}
function onHotwordDetected() {
console.log("[Snips Log] Hotword detected");
}
function onListeningStateChanged(listening) {
console.log("[Snips Log] " + (listening ? "Start" : "Stop") + " listening");
}
Comments
Please log in or sign up to comment.