@tshirtplease - Get a twitter photo on a t-shirt using the Rapanui API

Searches tweets for mentions of a @tshirtplease. If they have an image attached, and they are not a retweet, the image gets sent to the Rapanui API (https://rapanui.io) to be put on a t-shirt. The flow then replies to the original tweeter with a link where they can buy the t-shirt. Accepts the following hashtags as options:

#womens - The reply tweet links to a women's cut t-shirt rather than the default men's/unisex cut.

#edit - The reply tweet links to an online design-your-own-t-shirt tool that has the image preloaded; where the user can resize, recolour, add text, and choose from a wide range of garments and colours.

[
    {
        "id": "2065495e.df9ab6",
        "type": "twitter in",
        "twitter": "",
        "tags": "@tshirtplease",
        "user": "false",
        "name": "",
        "topic": "tweets",
        "x": 127.75,
        "y": 119.75000190734863,
        "z": "c3aed0d3.3ce58",
        "wires": [
            [
                "c71c3866.38e3c8"
            ]
        ]
    },
    {
        "id": "c71c3866.38e3c8",
        "type": "function",
        "name": "Process Request",
        "func": "if (typeof msg.tweet.entities.media != 'undefined' && typeof msg.tweet.retweeted_status == 'undefined')\n{\n\tvar image = msg.tweet.entities.media[0];\n\tvar image_url = encodeURIComponent(image.media_url);\n\t\n\tvar item_code = \"RNA1\";\n\tvar landing_page = \"product\";\n\t\n\tif (typeof msg.tweet.entities.hashtags != 'undefined')\n\t{\n\t\tmsg.tweet.entities.hashtags.forEach(function(hashtag) {\n\t\t    if (hashtag['text'] == \"womens\")\n\t\t    {\n\t\t    \titem_code = \"RNB1\";\n\t\t    }\n\t\t    if (hashtag['text'] == \"edit\")\n\t\t    {\n\t\t    \tlanding_page = \"customise\";\n\t\t    }\n\t\t});\n\t}\n\t\n\tvar msg = {\n\t\tpayload: image_url,\n\t\tuser: msg.tweet.user.screen_name,\n\t\titem_code: item_code,\n\t\tlanding_page: landing_page\n\t};\n\t\n\treturn [ msg, null ];\n}\n",
        "outputs": "2",
        "x": 252.69445037841797,
        "y": 227.9444522857666,
        "z": "c3aed0d3.3ce58",
        "wires": [
            [
                "177f77d4.e88088"
            ],
            []
        ]
    },
    {
        "id": "177f77d4.e88088",
        "type": "http request",
        "name": "Send API Request",
        "method": "GET",
        "url": "https://rapanuiclothing.com/api-access-point/?api_key=[[API key here - get at https://rapanui.io]] &item_code={{item_code}}&image_url={{payload}}&product_name=T-Shirt%20by%20@{{user}}&product_url_prefix=tshirtplease&landing_page={{landing_page}}",
        "x": 411.0277671813965,
        "y": 346.4722261428833,
        "z": "c3aed0d3.3ce58",
        "wires": [
            [
                "c99e31f5.3661d"
            ]
        ]
    },
    {
        "id": "e328fd00.1cd7",
        "type": "twitter out",
        "twitter": "",
        "name": "Reply",
        "x": 880.0000114440918,
        "y": 467.6111125946045,
        "z": "c3aed0d3.3ce58",
        "wires": []
    },
    {
        "id": "c99e31f5.3661d",
        "type": "function",
        "name": "Process API Response",
        "func": "if (msg.statusCode == 200)\n{\n\tvar messages = [\n\t\t\"Your wish is my command\",\n\t\t\"Here you go. Enjoy!\",\n\t\t\"oky doky, here you go...\",\n\t\t\"Looking good\",\n\t\t\"Abracadabra\",\n\t\t\"Zingazing ahhhh\",\n\t\t\"hey presto!\",\n\t\t\"Straight back at ya\",\n\t\t\"roger that, here goes\",\n\t\t\"T to the S to the H to the IRT\",\n\t\t\"aye aye skipper\",\n\t\t\"open sesame\"\n\t];\n\t\n\tvar hashtags = [\n\t\t\"#tshirt\",\n\t\t\"#eco\",\n\t\t\"#design\",\n\t\t\"#organic\",\n\t\t\"#print\",\n\t\t\"#fashion\"\n\t];\n\t\n\tvar hashtags2 = [\n\t\t\"#trend\",\n\t\t\"#tech\",\n\t\t\"#raspi\",\n\t\t\"#hack\",\n\t\t\"#wearables\",\n\t\t\"#FashionTech\"\n\t];\n\t\n\tvar message = messages[Math.floor(Math.random() * messages.length)];\n\tvar hashtag = hashtags[Math.floor(Math.random() * hashtags.length)];\n\tvar hashtag2 = hashtags2[Math.floor(Math.random() * hashtags2.length)];\n\t\n\tif (msg.payload.indexOf(\"https://tshirtplease.rapanuistore.com/design-your-own-t-shirt/\") != -1)\n\t{\n\t\turl = msg.payload.replace(\"https://tshirtplease.rapanuistore.com/design-your-own-t-shirt\", \"http://rapanui.co/tsp-edit\");\n\t\turl = msg.payload.replace(\"?colour=White\", \"\");\n\n\t}\n\telse\n\t{\n\t \turl = msg.payload.replace(\"https://tshirtplease.rapanuistore.com\", \"http://rapanui.co\");\n\t}\n\t\n\tmsg.payload = \"@\" + msg.user + \" \" + message + \" > \" + url + \" \" + hashtag + \" \" + hashtag2;\n\t\n\tfollowup_msg = {\n\t\tpayload: \"@\" + msg.user + \" p.s. this was powered by the Rapanui API, a #RaspberryPi and #NodeRED. Find out more > http://rapanui.co/tshirtplease/\"\n\t}\n\t\n\treturn [ msg, followup_msg ];\n}\nelse if (msg.payload.indexOf(\"Sorry, the design file resolution must be at least\") != -1)\n{\n\tmsg.payload = \"@\" + msg.user + \" Sorry, that image was too small. It must be at least 500x500px, but we recommend 1500px or over for best results.\";\n\treturn [ msg, null ];\n}\nelse\n{\n\tmsg.payload = \"@\" + msg.user + \" Sorry, something went wrong.\";\n\treturn [ msg, null ];\n}\n",
        "outputs": "2",
        "x": 587.4444274902344,
        "y": 475.6111145019531,
        "z": "c3aed0d3.3ce58",
        "wires": [
            [
                "e328fd00.1cd7"
            ],
            [
                "d2efe647.2d1018"
            ]
        ]
    },
    {
        "id": "d2efe647.2d1018",
        "type": "delay",
        "name": "Delay",
        "pauseType": "delay",
        "timeout": "7",
        "timeoutUnits": "seconds",
        "rate": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 880.3332862854004,
        "y": 545.1944389343262,
        "z": "c3aed0d3.3ce58",
        "wires": [
            [
                "1314c533.eceb3b"
            ]
        ]
    },
    {
        "id": "1314c533.eceb3b",
        "type": "twitter out",
        "twitter": "",
        "name": "Followup response",
        "x": 1059.1943969726562,
        "y": 545.1944522857666,
        "z": "c3aed0d3.3ce58",
        "wires": []
    }
]
js-wheeler

Flow Info

created 2 years, 4 months ago

Node Types

Core
  • delay (x1)
  • function (x2)
  • http request (x1)
  • twitter in (x1)
  • twitter out (x2)

Tags

  • twitter
  • clothing
  • t-shirt
  • api
  • rapanui
  • iotshirt
  • tshirtplease
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option