dvargas92495 / SmartBlocks

Useful examples from developer community for Roam42 SmartBlocks
147 stars 7 forks source link

Roam JSON to Webhook SmartBlock #204

Open mlava opened 3 years ago

mlava commented 3 years ago

โœ‚๏ธ Copy of your #42SmartBlock from Roam

Roam JSON to Webhook 0.6.zip

๐Ÿ“‹ Describe the SmartBlock

This SmartBlock allows you to post a parent block and its children as JSON to a webhook. This could be Zapier, IFTTT, Integromat or Pipedream. Others might work but might need some tweaks to the code.

For Zapier, Integromat and Pipedream:

For IFTTT:

Note that the limited utility of the IFTTT webhook is a limitation of IFTTT not this script... ๐Ÿ˜๐Ÿคจ

Completed to fulfill a bounty posted by @syncretizm on Twitter. https://twitter.com/syncretizm/status/1359751288859185152

โœ… Describe any prerequisites or dependencies that are required for this SmartBlock

Roam42.

Zapier Premium. IFTTT. Integromat. Pipedream. Or another service that accepts webhooks with JSON data payloads.

๐Ÿ“ท Screenshot of your #42SmartBlock workflow/template from Roam

image

This is an example of a block that might be used to create a calendar entry. However, you can put whatever information you like in the block.

Whatever is to left of the : in the child blocks will become a key and the value to the right will become a value. The parent block text is inserted into the json file as title.

The object will look like: {"title":"lunch with John","Date":"tomorrow","Time":"1130 am","Location":"Rialto Towers"}

(IFTTT: {"value1":"lunch with John","value2":"tomorrow","value3":"1130 am"} )

You will then have access to the title and each of the attributes as data in Zapier to send to another app. You can then do whatever you like with those key:value pairs.

An alternate example might be:

image

For which the JSON object will look like:

{"title":"Digital Minimalism","Author":"Cal Newport","Keywords":"books","Full Title":"Digital Minimalism"}

(IFTTT: {"value1":"Digital Minimalism","value2":"Cal Newport","value3":"books"} )

This would be useful for an entirely different type of Zap.

๐Ÿ’ก Additional Info

https://www.loom.com/share/c361eaa60267456098cc141c1499a913


I have a shared Roam Research Graph containing all of my Roam42 SmartBlocks, RoamJS and RoamCSS scripts.

You can find it here.

PJJPtx commented 3 years ago

I adapted this to send a Google Hangouts Chat message to my team chat room with Integromat --> GChat I had to change the code line 31 (below) in order to get the data right. "data": JSON.stringify(blocks) to "data": blocks

BTW, this is AWESOME! Thank you for making this happen.

mlava commented 3 years ago

Thanks, Jason. New version for download in the first post which detects the webhook URL for either Zapier, Pipedream or Integromat, and then modifies the ajax call as needed. Cheers!

Calhistorian commented 3 years ago

I wonder if this was my problem this morning. I was trying to convert it for IFTTT, which requires a 3 value JSON data package and it was not accepting the JSON even though it would create the event.

mlava commented 3 years ago

Hi Mark @Calhistorian Can you clarify what you mean? Or maybe send me the required format and I will see if we can make a version for IFTTT. Cheers! Mark

Edit: I found this format?

Make a POST or GET web request to:

https://maker.ifttt.com/trigger/{event}/with/key/{key}

With an optional JSON body of:

{ "value1" : "", "value2" : "", "value3" : "" }

I will modify the script to do this for IFTTT tonight.

mlava commented 3 years ago

New version in the first post.

Allows for IFTTT webhooks @Calhistorian

PJJPtx commented 3 years ago

I actually use Integromat, Zapier, and IFTTT. I have multiple webhooks at each service for various actions. Rather than make individual copies of the script that each read a different 42Setting, is there a way to have 42Settings for each webhook and pass to the script the exact one I am wanting it to use? For instance, I have several webhooks that are all Integromat.

mlava commented 3 years ago

Hi Jason. Yeah, I've been pondering that too. You can send data to SBs with a button and then do different things depending on the data, but I don't know how to do it with the jj trigger and I don't think you really want to have to put a button there before triggering the SB.

Perhaps you could include a string in the text item in Roam that is parsed and then chooses which workflow to follow. I imagine it would be quite idiosyncratic, and need personalisation for each user.

I'll ponder how the flow might work, but I had already been considering this use case and hadn't gotten much further than multiple copies of the block with different settings, I'm afraid...

mlava commented 3 years ago

v0.5 in first post.

This version handles the situation if you don't use a delimiter in your child block.

As there isn't a key defined (no delimiter) it will use 'string' instead. i.e.

For Zapier, Integromat and Pipedream, where n is the order within number of non-delimited child blocks you have, it will send "stringn":"string of text"

For IFTTT it will still send value1 etc as before.

PJJPtx commented 3 years ago

I would like to see if this code could be modified to do the following so I can easily move tasks to Asana one at a time without having to create the child blocks. What I am looking to do is this:

Steps to move task to Asana

  1. Grab the text of the current block
  2. Remove the {{[[TODO]]}}
  3. Send to Webhook with Assignee as me@mydomain.com
  4. Replace the {{[[TODO]]}} with {{[[DONE]]}}
  5. Add #Zapped to the end of the text
  6. Write the new text back over the existing text {{[[DONE]]}} Sample Task #Zapped

How hard would that be? My JS skills are lacking.

mlava commented 3 years ago

Updated to v 0.6.

Thanks @PJJPtx for reporting issue with block refs that contain hyphens and creating the fix.

@PJJPtx re your question from here - let me take a look and get back to you.


I have a shared Roam Research Graph containing all of my Roam42 SmartBlocks, RoamJS and RoamCSS scripts.

You can find it here.