Skip to content

Instantly share code, notes, and snippets.

@yoursunny
Last active July 10, 2016 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoursunny/69113aff0ab2e8215e0b8ebee0adcb04 to your computer and use it in GitHub Desktop.
Save yoursunny/69113aff0ab2e8215e0b8ebee0adcb04 to your computer and use it in GitHub Desktop.
Repost Twitter to Facebook with Losant and IFTTT https://yoursunny.com/t/2016/twitter-ifttt/
{
"globals": [
{
"key": "oauth_consumer_key",
"type": "string"
},
{
"key": "oauth_consumer_secret",
"type": "string"
},
{
"key": "oauth_user_token",
"type": "string"
},
{
"key": "oauth_user_secret",
"type": "string"
},
{
"key": "ifttt_maker_key",
"type": "string"
}
],
"triggers": [
{
"type": "virtualButton",
"meta": {
"category": "trigger",
"name": "virtualButton",
"label": "manual trigger",
"x": 240,
"y": 20,
"uiId": "Sy6fvtvG"
},
"config": {
},
"key": "573a06499673780100556fd2-S127tFvf",
"outputIds": [
[
"SJwRt9Df"
]
]
},
{
"type": "timer",
"meta": {
"category": "trigger",
"name": "timer",
"label": "every 3 minutes",
"x": 40,
"y": 20,
"uiId": "SJ88J2vG"
},
"config": {
"seconds": 180
},
"key": "f0f7bb60274611e68d83df80f0eac09d",
"outputIds": [
[
"SJwRt9Df"
]
]
}
],
"nodes": [
{
"type": "RawFunctionNode",
"meta": {
"category": "logic",
"name": "function",
"label": "OAuth sign",
"x": 80,
"y": 420
},
"config": {
"script": "eval.call(null, payload.js.cryptojs.body);\neval.call(null, payload.js.oauth.body);\ndelete payload['js'];\n\n\nvar oauth = OAuth({\n consumer: {\n public:payload.globals.oauth_consumer_key,\n secret:payload.globals.oauth_consumer_secret\n },\n signature_method:'HMAC-SHA1'\n});\n\nvar token = {\n public:payload.globals.oauth_user_token,\n secret:payload.globals.oauth_user_secret\n};\n\npayload.header = oauth.toHeader(oauth.authorize(payload.request, token));"
},
"id": "rJSXuFDz",
"outputIds": [
[
"ryHdzqvM"
]
]
},
{
"type": "DebugNode",
"meta": {
"category": "output",
"name": "debug",
"label": "Twitter API debug",
"x": 80,
"y": 580,
"description": ""
},
"config": {
"message": ""
},
"id": "HkLNuFPz",
"outputIds": [
]
},
{
"type": "HttpNode",
"meta": {
"category": "data",
"name": "http",
"label": "load crypto-js",
"x": 80,
"y": 260,
"description": ""
},
"config": {
"method": "GET",
"uriTemplate": "https:\/\/cdn.jsdelivr.net\/g\/crypto-js@3.1.2(rollups\/hmac-sha1.js+components\/enc-base64.js)",
"responsePath": "js.cryptojs",
"headerInfo": [
],
"bodyTemplate": {
}
},
"id": "ryWr3FDz",
"outputIds": [
[
"rJVr3FwG"
]
]
},
{
"type": "HttpNode",
"meta": {
"category": "data",
"name": "http",
"label": "load OAuth-1.0a",
"x": 80,
"y": 340,
"description": ""
},
"config": {
"method": "GET",
"uriTemplate": "https:\/\/cdn.rawgit.com\/ddo\/oauth-1.0a\/14eed75a02833a5892caaedc7dfa94eb608df92a\/oauth-1.0a.js",
"responsePath": "js.oauth",
"headerInfo": [
],
"bodyTemplate": {
}
},
"id": "rJVr3FwG",
"outputIds": [
[
"rJSXuFDz"
]
]
},
{
"type": "MutateNode",
"meta": {
"category": "logic",
"name": "mutate",
"label": "set API method",
"x": 80,
"y": 180,
"description": ""
},
"config": {
"rules": [
{
"type": "set",
"destination": "request.method",
"valueTemplate": "GET"
},
{
"type": "set",
"destination": "request.url",
"valueTemplate": "https:\/\/api.twitter.com\/1.1\/statuses\/user_timeline.json?trim_user=1&since_id={{processedId}}"
}
]
},
"id": "SkN8bcwG",
"outputIds": [
[
"ryWr3FDz"
]
]
},
{
"type": "HttpNode",
"meta": {
"category": "data",
"name": "http",
"label": "call Twitter API",
"x": 80,
"y": 500
},
"config": {
"method": "GET",
"uriTemplate": "{{request.url}}",
"responsePath": "response",
"headerInfo": [
{
"key": "Authorization",
"valueTemplate": "{{header.Authorization}}"
}
],
"bodyTemplate": {
}
},
"id": "ryHdzqvM",
"outputIds": [
[
"HkLNuFPz",
"HJlUYqPM"
]
]
},
{
"type": "RawFunctionNode",
"meta": {
"category": "logic",
"name": "function",
"label": "find next tweet",
"x": 320,
"y": 100,
"description": ""
},
"config": {
"script": "payload.tweet = null;\n\nvar tweets = payload.response.body;\nfor (var i = tweets.length - 1; i >= 0; --i) {\n var tweet = tweets[i];\n if (tweet.id_str > payload.processedId) {\n payload.tweet = tweet;\n break;\n }\n}\n\ndelete payload['header'];\ndelete payload['request'];\ndelete payload['response'];"
},
"id": "HJlUYqPM",
"outputIds": [
[
"rylG59Pf"
]
]
},
{
"type": "GetValueNode",
"meta": {
"category": "data",
"name": "get-value",
"label": "get processedId",
"x": 80,
"y": 100
},
"config": {
"keyName": "processedId",
"valuePath": "processedId",
"defaultValueType": "json",
"defaultValue": "null"
},
"id": "SJwRt9Df",
"outputIds": [
[
"SkN8bcwG"
]
]
},
{
"type": "ConditionalNode",
"meta": {
"category": "logic",
"name": "conditional",
"label": "has new tweet?",
"x": 320,
"y": 180,
"description": ""
},
"config": {
"expression": "{{tweet}} !== null"
},
"id": "rylG59Pf",
"outputIds": [
[
],
[
"ryHpT9vM"
]
]
},
{
"type": "DebugNode",
"meta": {
"category": "output",
"name": "debug",
"label": "new tweet debug",
"x": 320,
"y": 340
},
"config": {
"message": ""
},
"id": "HJVr9cwG",
"outputIds": [
]
},
{
"type": "ConditionalNode",
"meta": {
"category": "logic",
"name": "conditional",
"label": "is reply?",
"x": 540,
"y": 100,
"description": ""
},
"config": {
"expression": "{{tweet.in_reply_to_status_id_str}} != null"
},
"id": "S16Po9Pz",
"outputIds": [
[
"ryOEnqPz"
],
[
]
]
},
{
"type": "ConditionalNode",
"meta": {
"category": "logic",
"name": "conditional",
"label": "is 4sq?",
"x": 540,
"y": 260,
"description": ""
},
"config": {
"expression": "{{is4sq}}"
},
"id": "HkT0sqPf",
"outputIds": [
[
"Bk6Sk4iQ"
],
[
]
]
},
{
"type": "RawFunctionNode",
"meta": {
"category": "logic",
"name": "function",
"label": "is source 4sq",
"x": 540,
"y": 180
},
"config": {
"script": "payload.is4sq = \/foursquare.com\/.test(payload.tweet.source);"
},
"id": "ryOEnqPz",
"outputIds": [
[
"HkT0sqPf"
]
]
},
{
"type": "ConditionalNode",
"meta": {
"category": "logic",
"name": "conditional",
"label": "has picture?",
"x": 960,
"y": 20
},
"config": {
"expression": "{{tweet.entities}} && {{tweet.entities.media}} && {{tweet.entities.media[0].type}} == 'photo'"
},
"id": "Skfu39DM",
"outputIds": [
[
"HJ3n-oPM"
],
[
"B1xnMivz"
]
]
},
{
"type": "StoreValueNode",
"meta": {
"category": "data",
"name": "store-value",
"label": "set processedId",
"x": 320,
"y": 260
},
"config": {
"keyName": "processedId",
"valueType": "path",
"value": "tweet.id_str"
},
"id": "ryHpT9vM",
"outputIds": [
[
"S16Po9Pz",
"HJVr9cwG"
]
]
},
{
"type": "ConditionalNode",
"meta": {
"category": "logic",
"name": "conditional",
"label": "has link?",
"x": 820,
"y": 100
},
"config": {
"expression": "{{tweet.entities}} && {{tweet.entities.urls}} && {{tweet.entities.urls[0]}}"
},
"id": "HJ3n-oPM",
"outputIds": [
[
"S1w6cjPz"
],
[
"S1gUjowG"
]
]
},
{
"type": "RawFunctionNode",
"meta": {
"category": "logic",
"name": "function",
"label": "choose photo size",
"x": 1140,
"y": 100
},
"config": {
"script": "var media = payload.tweet.entities.media[0];\nvar maxSizeKey = false, maxSize = 0;\nfor (var sizeKey in media.sizes) {\n var sizeObj = media.sizes[sizeKey];\n var size = sizeObj.w * sizeObj.h;\n if (size > maxSize) {\n maxSize = size;\n maxSizeKey = sizeKey;\n }\n}\n\npayload.photoUrl = media.media_url_https;\nif (maxSizeKey) {\n payload.photoUrl += ':' + maxSizeKey;\n}"
},
"id": "B1xnMivz",
"outputIds": [
[
"HJtToiwG"
]
]
},
{
"type": "MutateNode",
"meta": {
"category": "logic",
"name": "mutate",
"label": "prepare text",
"x": 740,
"y": 180,
"description": ""
},
"config": {
"rules": [
{
"type": "set",
"destination": "ifttt_event",
"valueTemplate": "twttr_text"
},
{
"type": "set",
"destination": "ifttt.value1",
"valueTemplate": "{{tweet.text}}"
}
]
},
"id": "S1w6cjPz",
"outputIds": [
[
"ryS63swz"
]
]
},
{
"type": "MutateNode",
"meta": {
"category": "logic",
"name": "mutate",
"label": "prepare link",
"x": 940,
"y": 180
},
"config": {
"rules": [
{
"type": "set",
"destination": "ifttt_event",
"valueTemplate": "twttr_link"
},
{
"type": "set",
"destination": "ifttt.value1",
"valueTemplate": "{{tweet.text}}"
},
{
"type": "set",
"destination": "ifttt.value2",
"valueTemplate": "{{tweet.entities.urls[0].expanded_url}}"
}
]
},
"id": "S1gUjowG",
"outputIds": [
[
"ryS63swz"
]
]
},
{
"type": "MutateNode",
"meta": {
"category": "logic",
"name": "mutate",
"label": "prepare photo",
"x": 1140,
"y": 180
},
"config": {
"rules": [
{
"type": "set",
"destination": "ifttt_event",
"valueTemplate": "twttr_photo"
},
{
"type": "set",
"destination": "ifttt.value1",
"valueTemplate": "{{tweet.text}}"
},
{
"type": "set",
"destination": "ifttt.value2",
"valueTemplate": "{{photoUrl}}"
}
]
},
"id": "HJtToiwG",
"outputIds": [
[
"ryS63swz"
]
]
},
{
"type": "HttpNode",
"meta": {
"category": "output",
"name": "http",
"label": "call IFTTT maker",
"x": 940,
"y": 340,
"description": ""
},
"config": {
"method": "POST",
"uriTemplate": "https:\/\/maker.ifttt.com\/trigger\/{{ifttt_event}}\/with\/key\/{{globals.ifttt_maker_key}}",
"responsePath": "ifttt_response",
"headerInfo": [
{
"key": "Content-Type",
"valueTemplate": "application\/json"
}
],
"bodyTemplate": "{{ifttt_body}}"
},
"id": "B1BXnsPM",
"outputIds": [
[
"B1hs2jwf"
]
]
},
{
"type": "DebugNode",
"meta": {
"category": "output",
"name": "debug",
"label": "IFTTT debug",
"x": 940,
"y": 420,
"description": ""
},
"config": {
"message": ""
},
"id": "B1hs2jwf",
"outputIds": [
]
},
{
"type": "JsonEncodeNode",
"meta": {
"category": "logic",
"name": "json-encode",
"label": "encode IFTTT values",
"x": 940,
"y": 260,
"description": ""
},
"config": {
"source": "ifttt",
"destination": "ifttt_body"
},
"id": "ryS63swz",
"outputIds": [
[
"B1BXnsPM"
]
]
},
{
"type": "RawFunctionNode",
"meta": {
"category": "logic",
"name": "function",
"label": "full RT text",
"x": 540,
"y": 340,
"description": ""
},
"config": {
"script": "if (payload.tweet.retweeted_status) {\n var m = payload.tweet.text.match(\/^(RT @[^:]+: )\/);\n if (m) {\n payload.tweet.text = m[1] + payload.tweet.retweeted_status.text;\n }\n}"
},
"id": "Bk6Sk4iQ",
"outputIds": [
[
"Skfu39DM"
]
]
}
],
"name": "twttr-to-ifttt",
"enabled": true,
"description": "",
"applicationId": "56da5a13de4d15010072f046",
"_type": "flow",
"_exportDate": "2016-07-10T01:07:35.994Z"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment