Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
casdr committed May 1, 2018
0 parents commit affd5f8
Show file tree
Hide file tree
Showing 13 changed files with 1,346 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# node-red-contrib-freshdesk
Freshdesk nodes for NodeRED
25 changes: 25 additions & 0 deletions fd-add-reply.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script type="text/javascript">
RED.nodes.registerType('fd-add-reply', {
category: 'function',
color: '#4fb29d',
inputs: 1,
outputs: 1,
defaults: {
name: {value: ""},
api: {value: "", type: "fd-config"}
},
label: function (){
return this.name || "Add reply to ticket";
}
});
</script>
<script type="text/x-red" data-template-name="fd-add-reply">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name">
</div>
<div class="form-row">
<label for="node-input-api"><i class="icon-gear"></i> Freshdesk</label>
<input type="text" id="node-input-api">
</div>
</script>
20 changes: 20 additions & 0 deletions fd-add-reply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = function(RED) {
function FDAddReplyNode(n) {
RED.nodes.createNode(this,n);
var node = this;
node.api = RED.nodes.getNode(n.api);
node.on('input', function(msg) {
msg.payload.freshdesk_reply_data.user_id = msg.payload.freshdesk_reply_data.user_id || parseInt(node.api.defaultuser);
node.warn(msg.payload.freshdesk_reply_data);
node.api.fd.createReply(msg.payload.freshdesk_ticket.id, msg.payload.freshdesk_reply_data, function (err, data) {
if (err) {
node.error(err);
} else {
msg.payload.freshdesk_reply = data;
node.send(msg);
}
});
});
}
RED.nodes.registerType('fd-add-reply', FDAddReplyNode);
}
32 changes: 32 additions & 0 deletions fd-config.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<script type="text/javascript">
RED.nodes.registerType('fd-config', {
category: 'config',
defaults: {
subdomain: {value: "", required:true},
key: {value: "", required:true},
defaultuser: {value: "", required:true, type: "integer"},
defaultgroup: {value: "", required:true, type: "integer"}
},
label: function () {
return this.subdomain + ".freshdesk.com";
}
});
</script>
<script type="text/x-red" data-template-name="fd-config">
<div class="form-row">
<label for="node-config-input-subdomain"><i class="icon-globe"></i> Subdomain</label>
<input type="text" id="node-config-input-subdomain">
</div>
<div class="form-row">
<label for="node-config-input-key"><i class="icon-pencil"></i> API key</label>
<input type="text" id="node-config-input-key">
</div>
<div class="form-row">
<label for="node-config-input-defaultuser"><i class="icon-user"></i> Default user ID</label>
<input type="text" id="node-config-input-defaultuser">
</div>
<div class="form-row">
<label for="node-config-input-defaultgroup"><i class="icon-th-large"></i> Default group ID</label>
<input type="text" id="node-config-input-defaultgroup">
</div>
</script>
20 changes: 20 additions & 0 deletions fd-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var Freshdesk = require('freshdesk-api');

module.exports = function(RED) {
function FDConfigurationNode(n) {
RED.nodes.createNode(this,n);
this.subdomain = n.subdomain;
this.key = n.key;

this.defaultuser = n.defaultuser;
this.defaultgroup = n.defaultgroup;

var node = this;
setTimeout(function () { node.warn(n); }, 2000);

if (this.subdomain) {
this.fd = new Freshdesk('https://' + this.subdomain + '.freshdesk.com', this.key);
}
}
RED.nodes.registerType("fd-config", FDConfigurationNode);
}
25 changes: 25 additions & 0 deletions fd-create-ticket.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script type="text/javascript">
RED.nodes.registerType('fd-create-ticket', {
category: 'function',
color: '#4fb29d',
inputs: 1,
outputs: 1,
defaults: {
name: {value: "Create new ticket"},
api: {value: "", type: "fd-config"}
},
label: function (){
return this.name || "Create new ticket";
}
});
</script>
<script type="text/x-red" data-template-name="fd-create-ticket">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name">
</div>
<div class="form-row">
<label for="node-input-api"><i class="icon-tag"></i> Freshdesk</label>
<input type="text" id="node-input-api">
</div>
</script>
20 changes: 20 additions & 0 deletions fd-create-ticket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = function(RED) {
function FDCreateTicketNode(n) {
RED.nodes.createNode(this,n);
var node = this;
node.api = RED.nodes.getNode(n.api);
node.on('input', function(msg) {
msg.payload.freshdesk_ticket_data.requester_id = msg.payload.freshdesk_ticket_data.requester_id || parseInt(node.api.defaultuser);
msg.payload.freshdesk_ticket_data.group_id = msg.payload.freshdesk_ticket_data.group_id || parseInt(node.api.defaultgroup);
node.api.fd.createTicket(msg.payload.freshdesk_ticket_data, function (err, data) {
if (err) {
node.error(err);
} else {
msg.payload.freshdesk_ticket = data;
node.send(msg);
}
});
});
}
RED.nodes.registerType('fd-create-ticket', FDCreateTicketNode);
}
26 changes: 26 additions & 0 deletions fd-search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script type="text/javascript">
RED.nodes.registerType('fd-search', {
category: 'function',
color: '#4fb29d',
inputs: 1,
outputs: 1,
defaults: {
name: {value: "Search for tickets"},
api: {value: "", type: "fd-config"}
},
label: function (){
return this.name || "Search for tickets";
}
});
</script>
<script type="text/x-red" data-template-name="fd-search">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name">
</div>

<div class="form-row">
<label for="node-input-api"><i class="icon-tag"></i> Freshdesk</label>
<input type="text" id="node-input-api">
</div>
</script>
18 changes: 18 additions & 0 deletions fd-search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = function(RED) {
function FDSearchNode(n) {
RED.nodes.createNode(this,n);
var node = this;
node.api = RED.nodes.getNode(n.api);
node.on('input', function(msg) {
node.api.fd.filterTickets(msg.payload.freshdesk_query, function (err, data) {
if (err) {
node.error(err);
} else {
msg.payload.freshdesk_search = data;
node.send(msg);
}
});
});
}
RED.nodes.registerType('fd-search', FDSearchNode);
}
Loading

0 comments on commit affd5f8

Please sign in to comment.