Skip to content

Instantly share code, notes, and snippets.

View johnathanDOS's full-sized avatar
🌵
[ • • ]

Johnathan Ortiz-Sonnen johnathanDOS

🌵
[ • • ]
View GitHub Profile
@johnathanDOS
johnathanDOS / YesNoSkill.js
Created November 22, 2019 17:19
YesNoSkill.js
misty.Debug("Starting my skill");
_yesnoURL = "https://yesno.wtf/api"
// Parse the response data to get the current condition in _params.city
// and print this in a string to the dev console in the Skill Runner
// web page.
function _SendExternalRequest(data) {
_data = JSON.parse(data.Result.ResponseObject.Data)
_answer = _data.answer.toLowerCase();
@johnathanDOS
johnathanDOS / Misty_GetFingerprintData_Sample.js
Created November 8, 2019 15:02
A bit of sample code that shows how Misty can read fingerprint scan data from an Arduino board through the UART serial port on her back.
// ----------------------- Finger Print Sensor -----------------
// Updates the fingerPrintActivated key to set the state of the skill
// so that Misty is ready to receive data from the fingerprint scanner
_enableFingerPrint()
function _enableFingerPrint() {
misty.Set("fingerPrintActivated", false, false);
}
// Starts Misty listening for data from UART serial. Data that comes in
@johnathanDOS
johnathanDOS / photoBooth_sendPicture.js
Last active August 22, 2019 17:11
Sample sendPicture() function from Photo Booth skill
function sendPicture() {
misty.Debug("Sending Image to User");
// Sets up thee JSON body for the Twilio SMS API.
// Includes the phone number of the recipient and
// the URL for their photograph on Imgur
var jsonBody = {
'Body': '[••] Greetings from Misty!',
'From': '<number-to-send-from>',
'To': misty.Get("contact"),
'MediaUrl': misty.Get("imageLink")
@johnathanDOS
johnathanDOS / photoBooth_uploadPicture.js
Created August 22, 2019 05:49
Sample uploadPicture() function & callback from PhotoBooth skill
function uploadImage(imageData) {
// Sets up the JSON body for uploading the picture
var jsonBody = {
'image': imageData,
'type' : 'base64',
'album': '<album-name>
};
// Uploads the picture to a private album; then, passes Imgur
// response data into the _imageUploadResponse() callback
misty.SendExternalRequest("POST", "https://api.imgur.com/3/image", "Bearer", "<bearer-token>", JSON.stringify(jsonBody), false, false, "", "application/json", "_imageUploadResponse");
@johnathanDOS
johnathanDOS / photoBooth_takePictureCallback.js
Last active August 22, 2019 17:08
Example misty.TakePicture() callback function for PhotoBooth skill
function _TakePicture(data) {
var base64String = data.Result.Base64;
uploadImage(base64String);
}
@johnathanDOS
johnathanDOS / photoBooth_takePicture.js
Created August 22, 2019 05:44
Sample code showing how Misty would take a picture in the Photo Booth skill
if (data != [] && data.type == 'photo')
{
// Saves the user's contact info
misty.Set("contact", (data.phNumber).toString(), false);
// Changes display image, sets head position, and plays
// sounds to show she's taking a picture
misty.DisplayImage("DefaultEyes_SystemCamera.jpg");
misty.Pause(100);
misty.PlayAudio("DefaultSounds_Awe3.wav", 100);
misty.Set("pictureMode", true, false);
@johnathanDOS
johnathanDOS / photoBooth_PubNubRequests.js
Created August 22, 2019 05:43
Example of PubNub requests for Misty's Photo Booth skill
// Calls the keepActive() function every 15 seconds
misty.RegisterTimerEvent("keepActive", 15000, true);
// Sends a publish request to work around timeouts
function _keepActive() {
misty.SendExternalRequest("POST", "https://ps.pndsn.com/publish/<publish-key>/<subscribe-key/0/<channel-name>/myCallback", null, null, "{}", false, false, "", "application/json");
}
// Gets the message Twilio sends to PubNub and passes
@johnathanDOS
johnathanDOS / body.json
Created August 22, 2019 05:40
Sample JSON Body for PubNub request
{
'phNumber': contact,
'type': 'photo'
}
@johnathanDOS
johnathanDOS / photoBooth_PubNubURLSample
Created August 22, 2019 05:35
Example URL for PubNub
https://ps.pndsn.com/publish/<publish-key>/<subscribe-key>/0/<channel-name>/0?store=0&uuid=<client-name>
@johnathanDOS
johnathanDOS / photoBooth_twilioFunction.js
Created August 22, 2019 05:34
Example Twilio function for Misty's Photo Booth skill
exports.handler = function(context, event, callback) {
// Saves phone number to contact variable
var contact = event.UserIdentifier || "19294421336";
// Sends SMS to user
const replySms = {"actions": [{"say": "[••] Time to Pose"}]};
const replyErrorSms = {"actions": [{"say": "[••] Oops an error occured, Could you please try again.."}]};
const axios = require('axios')
// The PubNub URL includes publish/subscribe keys, a