-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
source .env | ||
echo Logging into Stitch | ||
stitch-cli login --username=$STITCH_USERNAME --api-key=$STITCH_API_KEY | ||
echo Importing from project directory | ||
stitch-cli import --app-id=giphyresponder-mspiu --path=./stitch-app --strategy=merge | ||
echo Logging out | ||
stitch-cli logout | ||
echo Deploy complete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
source .env | ||
echo Logging into Stitch | ||
stitch-cli login --username=$STITCH_USERNAME --api-key=$STITCH_API_KEY | ||
echo Exporting Project to temp directory | ||
rm -rf tmp | ||
stitch-cli export --app-id=giphyresponder-mspiu --output=./tmp | ||
echo Copying to project directory | ||
cp -r ./tmp/. ./stitch-app | ||
rm -rf tmp | ||
echo Logging out | ||
stitch-cli logout | ||
echo Export complete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"id": "5aa022b5b8b998813e540599", | ||
"name": "anon-user", | ||
"type": "anon-user", | ||
"disabled": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"id": "5aa017b446224c87296031b9", | ||
"name": "api-key", | ||
"type": "api-key", | ||
"disabled": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"id": "5aa02c65b8b998813e6e8200", | ||
"name": "GiphySearch", | ||
"private": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
exports = function(search){ | ||
const giphyService = context.services.get("GiphyAPI"); | ||
return giphyService.get({ | ||
scheme: "http", | ||
host: "api.giphy.com", | ||
path: "/v1/gifs/search", | ||
query: { | ||
"api_key": ["dc6zaTOxFJmzC"], | ||
"q": [search], | ||
"rating": ["pg"], | ||
"limit": ["5"] | ||
}, | ||
headers: { | ||
"Content-Type": [ | ||
"application/json" | ||
] | ||
} | ||
}).then(payload => { | ||
const body = EJSON.parse(payload.body.text()); | ||
const data = body.data; | ||
let gifs = data.map(gif => { | ||
return { | ||
src: gif.images.fixed_height_small.url, | ||
url: gif.url, | ||
id: gif.id, | ||
title: gif.title | ||
}; | ||
}); | ||
return gifs; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"id": "5aa035b28f25b971a62d59c4", | ||
"name": "SendEmail", | ||
"private": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
exports = function(recipient, subData){ | ||
const sparkpostService = context.services.get("SparkPost"); | ||
return sparkpostService.post({ | ||
url: "https://api.sparkpost.com/api/v1/transmissions", | ||
body: JSON.stringify({ | ||
"campaign_id": "giphy-responder", | ||
"recipients": [ | ||
{ | ||
"address": recipient | ||
} | ||
], | ||
"content": { | ||
"template_id": "giphy-responder" | ||
}, | ||
"substitution_data": subData | ||
}), | ||
headers: { | ||
"Authorization": [ | ||
context.values.get("sp-api-key") | ||
], | ||
"Content-Type": [ | ||
"application/json" | ||
] | ||
} | ||
}).then(payload => { | ||
const body = EJSON.parse(payload.body.text()); | ||
return body.results; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"id": "5aa02b5acfb737497eb9bf42", | ||
"name": "GiphyAPI", | ||
"type": "http", | ||
"config": {}, | ||
"version": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"id": "5aa02bc7b8b998813e6d2983", | ||
"name": "GET", | ||
"actions": [ | ||
"get" | ||
], | ||
"when": { | ||
"%%args.url.host": "api.giphy.com" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"id": "5aa01881b8b998813e42cfb6", | ||
"name": "SparkPost", | ||
"type": "http", | ||
"config": {}, | ||
"version": 1 | ||
} |
12 changes: 12 additions & 0 deletions
12
stitch-app/services/SparkPost/incoming_webhooks/incoming/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"id": "5aa018d98f25b971a6f5ee77", | ||
"name": "incoming", | ||
"run_as_user_id": "", | ||
"run_as_user_id_script_source": "", | ||
"options": { | ||
"httpMethod": "POST", | ||
"secret": "purplemonkeydishwasher", | ||
"secretAsQueryParam": true | ||
}, | ||
"respond_result": false | ||
} |
35 changes: 35 additions & 0 deletions
35
stitch-app/services/SparkPost/incoming_webhooks/incoming/source.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
exports = function(payload) { | ||
const body = EJSON.parse(payload.body.text()); | ||
|
||
const relayMsg = body[0].msys.relay_message; | ||
const localpart = relayMsg.rcpt_to.split('@')[0]; | ||
const from = relayMsg.friendly_from || relayMsg.msg_from; | ||
const subject = relayMsg.content.subject; | ||
console.log('Email received from: ', from); | ||
console.log('Searching for: ', subject); | ||
context.functions.execute("GiphySearch", subject).then(gifs => { | ||
const mongodb = context.services.get("mongodb-atlas"); | ||
return mongodb.db('porg').collection('responses').insertOne({ | ||
"localpart": localpart, | ||
"from": from, | ||
"search": subject, | ||
"gifs": gifs, | ||
"relayMsg": relayMsg, | ||
"ts": new Date() | ||
}).then(result => { | ||
let subData = { | ||
search: subject, | ||
gifs: gifs | ||
}; | ||
return subData; | ||
}); | ||
}).then(subData => { | ||
console.log('Substitution Data: ', JSON.stringify(subData)); | ||
return context.functions.execute("SendEmail", from, subData); | ||
}).then(result => { | ||
console.log('Send Result: ', JSON.stringify(result)); | ||
return; | ||
}).catch(err => { | ||
console.log('Error: ', JSON.stringify(err)); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"id": "5aa037d2cfb737497ec8ff20", | ||
"name": "POST", | ||
"actions": [ | ||
"post" | ||
], | ||
"when": { | ||
"%%args.url.host": "api.sparkpost.com" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"id": "5ad23cb246224c054025b23e", | ||
"name": "mongodb-atlas", | ||
"type": "mongodb-atlas", | ||
"config": { | ||
"clusterName": "Cluster0" | ||
}, | ||
"version": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"id": "5ad23da5cfb737ad8f32be4b", | ||
"namespace": "porg.responses", | ||
"other_fields": {}, | ||
"write": {}, | ||
"read": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"app_id": "giphyresponder-mspiu", | ||
"config_version": 20180301, | ||
"name": "GiphyResponder", | ||
"security": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"id": "5aa03563b8b998813e7aa3a2", | ||
"name": "sp-api-key", | ||
"value": "<SPARKPOST_API_KEY>", | ||
"private": false | ||
} |