Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Receive a webhook using trellinator

Carlos Pozos Ochoa June 6, 2021

I have been trying to Receive a shopify webhook to my trellinator google app script. In my research I have found out that my code should run on doPost function and then send a 200 OK response.

I have performed some tests and my code is running fine, but the webhook keeps triggering as if it did not received the 200 OK response.

I know that trellinator uses doPost function to execute some code, and I do not know how to receive my webhook on top of trellinator platform. 

Below you can find the doPost function I am taltking about

function doPost(e)
{
var hooks = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Custom Webhooks");
var htmlOut = false;

//Here is were I execute my function
myFunction(e);

//My function ends
if(hooks)
{
new IterableCollection(hooks.getDataRange().getValues()).each(function(row)
{
if(this[row[0].trim()] &&(htmlOut === false))
{
htmlOut = this[row[0].trim()](e);
}
});
}

if(htmlOut === false)
{
if(e.postData)
{
var notifText = e.postData.contents;
var htmlOut = doPosting(notifText);
}

else
{
var htmlOut = HtmlService.createHtmlOutput("<p>Processed Notification</p>");
}
}

else
{
var htmlOut = HtmlService.createHtmlOutput("<p>Processed Notification</p>");
flushInfoBuffer();
}
return htmlOut;

}

1 answer

0 votes
Iain Dooley
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 6, 2021

@Carlos Pozos Ochoa I'll reply here as well as in Reddit :)

Note that you shouldn't ever need to edit any of the Trellinator files.

This is an undocumented feature, but just create a sheet in your Trellinator spreadsheet called "Custom Webhooks" then put your function names in the first column, no header column. So in your case you would just enter

myFunction

into cell A1.

These functions will be called before the Trellinator notification processor, if you return "true" from your function, processing will stop, that is the notification will not proceed to be passed into your Trellinator functions.

If you return "false" then the notification will be passed onto your Trellinator functions. So an example of a custom webhook might be something like this:

https://gist.github.com/iaindooley/c344cc62c08858736ce18e8cf920c44e

 

Carlos Pozos Ochoa June 8, 2021

Thank you Iain, I have tested the code you propose and it is executed right. The problem is that I should reply shopify in a 5 second window with the 200 OK response, but looking at my logs "myFunction" is taking longer than that time to reply, so the webhook is firing continously. Is there anyway I can add my function to your trellinator queue? So this way I can anwer inmediately to shopify and let my funciton execute later.

Iain Dooley
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 8, 2021

@Carlos Pozos Ochoa yep just use the same URL that is set up for all your other boards. You can see by running this piece of code:

https://gist.github.com/iaindooley/ee64dd680d1991ede55aa5cb7ef843bd

just grab your token from the Configuration tab and put it in there. You can use that webhook directly the same as you would use the published script URL, it just queues the requests and forwards them onto the script anyway

Like Carlos Pozos Ochoa likes this
Carlos Pozos Ochoa June 25, 2021

Awesome, it worked perfectly. Thank you very much for all your work and the knowledge you share. 

Like Iain Dooley likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events