How to pass data as GET params in webhook?


#1

I’m currently getting the Word of the Day from Longman Dictionary – what I’d like to do next is to use a webhook to send an email containing the Word of the Day. Has anyone figured out how to do this without running a local or virtual server?

I thought IFTTT would be the perfect solution for this since it has both an Email service and a Webhooks service, but alas I was not able to make it work because I couldn’t figure out how to pass the word and definition (see data below) as GET params in the webhook.

It would be awesome if Morph.io could offer a webhook POST composer like Customer.io so we can easily define the payload:

Another alternative is to offer the ability to send an email of the scraped content directly from the scraper settings page, e.g.:

Given this data:

{ id: 1,
   word: 'standardize',
   definition: 'to make all the things of one particular type the same as each other' }

I would like to be able to fill out a form like below to send out an email:

To: someone@domain.com
Subject: Word of the Day
Message:
Here is your word of the day!

{{word}}: {{definition}}

#2

Morph doesn’t natively integrate with any particular third party service provider, but within your scrapers you can use HTTP to communicate with any third party APIs you like. For example, I use these snippets of python code to post messages to slack and raise github issues from within my scrapers: https://github.com/polling-bot-4000/polling-bot/blob/master/polling_bot/brain.py

In order to send an email, you will need to write some code in your scraper which makes a POST request to your external email service’s endpoint. I’m not too familiar with IFTTT or nodejs, but fundamentally, you scraper will need to assemble a json payload object - it will probably look something like

{
    "to": "foo@bar.baz",
    "subject": "foo",
    "body": "bar, baz"
}

and then use the request library to assemble a HTTP request which POSTs that payload to your email service’s endpoint (I guess you’ll have a URL something like https://ifttt.com/email/send). You will probably also need to construct some custom header to pass an authentication token or api key or something.

Best of luck


#3

Thanks @chris48s for pointing me in the right direction. I now just need to find a way to do a POST request to the IFTTT to accomplish what I want.


#4

Check out the docs for request for more detail, but you’ll want to
use request.post.

Not tested, but I guess your code is probably going to end up looking something like this:

var request = require('request');

var payload = {
  "to": "foo@bar.baz",
  "subject": "foo",
  "body": "bar, baz"
};

request.post({
  headers: {'content-type' : 'application/json'},
  url: "http://foo.bar/baz'",
  body: payload
}, function(error, response, body){
  //optional callback
});

#5

Yes, you are correct. The great thing is IFTTT is already expecting a JSON payload, so I can just past row as the body (see readRows() in https://github.com/thdoan/longman_word_of_the_day/blob/master/scraper.js).