Difference between revisions of "Webhooks"

From Evil Mad Scientist Wiki
Jump to: navigation, search
Line 5: Line 5:
  
 
This feature is available in the main [[Axidraw_Software_Installation|Inkscape-based software]] as well as the [https://axidraw.com/doc/cli_api/ AxiDraw CLI] and [https://axidraw.com/doc/py_api/ AxiDraw Python module] APIs.
 
This feature is available in the main [[Axidraw_Software_Installation|Inkscape-based software]] as well as the [https://axidraw.com/doc/cli_api/ AxiDraw CLI] and [https://axidraw.com/doc/py_api/ AxiDraw Python module] APIs.
 +
  
 
=== Third-party services ===
 
=== Third-party services ===
  
 
Various internet services exist, both free and paid, that allow one to trigger different actions upon receipt of a webhook post. Two services that we are aware of, [http://ifttt.com IFTTT] and [http://integromat.com Integromat], offer free tiers that support webhooks. Similar, paid, services that support webhooks include Zapier and Automate.io. Any of these services provides an interface to receive webhooks without requiring coding.
 
Various internet services exist, both free and paid, that allow one to trigger different actions upon receipt of a webhook post. Two services that we are aware of, [http://ifttt.com IFTTT] and [http://integromat.com Integromat], offer free tiers that support webhooks. Similar, paid, services that support webhooks include Zapier and Automate.io. Any of these services provides an interface to receive webhooks without requiring coding.
 +
  
 
=== DIY; working without third-party services ===
 
=== DIY; working without third-party services ===
  
 
For custom integrations, it may be helpful to listen for and receive a webhooks with your own software. Webhooks are small-scale HTTP posts to a given URL and it is relatively straightforward (as far as these things go) to deploy a small web server for that purpose. A good article with some starting points is avaialable at [https://hackernoon.com/how-to-listen-for-webhooks-using-python-7g153uad hackernoon] for python and [https://medium.com/@BearerSH/consuming-webhooks-with-node-js-and-express-50e007fc7ae2 the Bearer blog] for node.js.   
 
For custom integrations, it may be helpful to listen for and receive a webhooks with your own software. Webhooks are small-scale HTTP posts to a given URL and it is relatively straightforward (as far as these things go) to deploy a small web server for that purpose. A good article with some starting points is avaialable at [https://hackernoon.com/how-to-listen-for-webhooks-using-python-7g153uad hackernoon] for python and [https://medium.com/@BearerSH/consuming-webhooks-with-node-js-and-express-50e007fc7ae2 the Bearer blog] for node.js.   
 +
  
 
=== Conditions for posting to the webhook ===
 
=== Conditions for posting to the webhook ===

Revision as of 00:20, 10 January 2022

  This wiki page is part of our AxiDraw documentation

Please click here to return to the AxiDraw overview.

Overview: Using Webhooks with AxiDraw

The AxiDraw software, starting with version 3.1, is capable of posting a Webhook (HTTP callback) at the end of a plot. This provides a method, when used in combination with various third-party services, for generating notifications such as mobile alerts or email when the AxiDraw finishes. Webhooks can also be used for custom integration with other software or hardware, to trigger other actions that should follow a plot.

This feature is available in the main Inkscape-based software as well as the AxiDraw CLI and AxiDraw Python module APIs.


Third-party services

Various internet services exist, both free and paid, that allow one to trigger different actions upon receipt of a webhook post. Two services that we are aware of, IFTTT and Integromat, offer free tiers that support webhooks. Similar, paid, services that support webhooks include Zapier and Automate.io. Any of these services provides an interface to receive webhooks without requiring coding.


DIY; working without third-party services

For custom integrations, it may be helpful to listen for and receive a webhooks with your own software. Webhooks are small-scale HTTP posts to a given URL and it is relatively straightforward (as far as these things go) to deploy a small web server for that purpose. A good article with some starting points is avaialable at hackernoon for python and the Bearer blog for node.js.


Conditions for posting to the webhook

Webhook alerts are only generated when a plot ends, by completion or being paused, and all four of the following conditions are met:

1. Webhooks are enabled, for example by the checkbox in the Preview & Alerts tab of AxiDraw Control
2. A document is being plotted with the Plot, Layers, or Resume tab, and
3. The document is being physically plotted, with preview mode disabled, and
4 A Webhook URL is provided

In any other case, the Webhook is not posted.


Data posted

When the AxiDraw finishes a plot and webhooks are enabled, the software will send data by the HTTP POST method to to the URL that you specify. The data posted is JSON formatted and contains three key/value pairs:

{ "value1" : "Document name", "value2" : "Elapsed time", "value3" : "Port" }

The elapsed time is a human-readable value with hours, minutes, and seconds. The "Port" value is that given as the Port option in the software, for example in the Config tab of AxiDraw Control. If you are using multiple AxiDraw machines, this can be used in combination with the AxiDraw Naming feature to identify which particular AxiDraw has finished plotting.


Setting up mobile notifications with IFTTT

Here, in some detail, is how to set up app-based mobile notifications using the IFTTT service. Slight variations on this can be used to select other actions once the webhook is received by IFTTT.

1. Create a free account at IFTTT.com. For mobile alerts, install their mobile app as well.

2. Click the Create button to begin creation of an “applet”.

3. Click the Add button next to “If This”.

4. On the next screen, “Choose a service,” type “webhooks” in the search box. Then, click the Webhooks button to select it.

5. On the next screen, “Choose a trigger”, select “Receive a web request”.

6. The next screen, “Complete trigger fields”, asks for an Event Name. Give it a name, maybe “axidraw_done”, then click the Create Trigger.

7. Click the Add button next to “Then That”.

8. Select and configure an action to trigger when a plot completes. We recommend the “Notifications” service, which gives mobile notifications from the IFTTT app, on Android or iOS. If using Notifications, choose the basic “Send a notification from the IFTTT app” option.

9. Complete the “action fields” for the action that you have selected. For Notifications, the text can be as simple as “Plot done”, or using data fields, as complex as “AxiDraw Template:Value3 finished document Template:Value1 in Template:Value2.” Click the Create Action button to finish adding it. Then click Continue to review.

10. Optionally rename the applet; click Finish to complete.

11. The completed applet should be displayed similar to here, with a brief summary of its settings. Click the “webhook” symbol on the applet; shown circled here, and then click the Documentation button.

12. On this page is the webhook URL.

Fill in the {event} placeholder with your Event Name (“axidraw_done”, in our example) to get the final URL. The webhook URL typically looks like:

        https://maker.ifttt.com/trigger/axidraw_done/with/key/PRIVATE_KEY

13. Copy and paste the full URL into the Webhook URL field of Axidraw Control.