-
-
Notifications
You must be signed in to change notification settings - Fork 100
Custom Script IFTTT
Erik Bigler edited this page Mar 19, 2018
·
4 revisions
Here is the first version of IFTTT-Connection Custom Script for Firebot 4.9.0.
Save this as ifttt-connection.js
inside %appdata%\firebot\firebot-data\user-settings\scripts
.
The IFTTT Connection script should now be available in the Custom Script effect, if you don't see the Custom Script effect please make sure that you have turned in on in Settings > Advanced > Custom Script Effects.
Then follow the steps here to set up the script for use with Philips Hue!
exports.getDefaultParameters = function() {
return new Promise((resolve, reject) => {
resolve({
eventName: {
type: "string",
description: "Insert Event Name here",
secondaryDescription: "This is the name of the event to trigger via IFTTT. Check https://ifttt.com/my_applets for available Applets and their event names.",
default: "[INSERT EVENT NAME HERE]"
},
iftttKey: {
type: "string",
description: "Insert IFTTT Key here",
secondaryDescription: "This is the key you have been assigned from the IFTTT WebHook Service. https://ifttt.com/maker",
default: "[INSERT YOUR KEY HERE]"
},
tellChat: {
type: "enum",
options: ["No", "Yes"],
description: "Should we post a message in chat about the action?",
default: "No"
},
chatMessageTemplate: {
type: "string",
description: "Chat action message",
secondaryDescription: "This message is shown in chat when someone uses the command/button.",
default: "$(user) just flipped the switch!"
},
chatter: {
type: "enum",
options: ["Streamer", "Bot"],
default: "Streamer",
description: "Send From",
secondaryDescription: "Which account to send the messages from."
}
});
});
};
exports.getScriptManifest = function() {
return {
name: "IFTTT Connection",
description: "Allows you to connect Firebot to an IFTTT Applet. You can make your own Applet here: https://ifttt.com/create/",
author: "ThePerry",
version: "0.5"
};
};
exports.run = function(runRequest) {
let username = runRequest.user.name;
let tellChat = runRequest.parameters.tellChat;
// Return a Promise object
return new Promise((resolve, reject) => {
let url = "https://maker.ifttt.com/trigger/" + runRequest.parameters.eventName + "/with/key/" + runRequest.parameters.iftttKey;
let messageTemplate = runRequest.parameters.chatMessageTemplate;
const request = runRequest.modules.request;
request(url, function (error, response1, data) {
let response = {};
if (!error) {
// Got response from IFTTT.
let content = data;
let message;
if (content.statusCode === 404) {
message = 'Something wrong happened while talking to IFTTT!';
} else {
message = messageTemplate
.replace("$(user)", username);
}
if (tellChat === "Yes") {
// Create a success response
response = {
success: true,
effects: [
{
type: EffectType.CHAT,
message: message,
chatter: runRequest.parameters.chatter
}
]
};
} else {
response = {
success: true
};
}
} else {
// We had an error with the request. So, create an error popup in Firebot.
// Create a failed response
response = {
success: false,
errorMessage: 'There was an error retrieving data from the IFTTT Service'
};
}
// Resolve Promise with the response object
resolve(response);
});
});
};
Still need help? Come chat with us in the #help channel of our Discord server.