"Webhook" Vals #192
Replies: 2 comments 1 reply
-
I love these ideas! Zapier in particular gets a lot out of having generic triggers and actions. There are a lot of vals that accept webhooks like what you're talking about, but because they also contain other "action"-specific stuff, they're not as re-composable as one might wish. For example this val handles stripe webhooks and then does other stuff: https://www.val.town/v/stevekrouse/newStripeEvent This val similarly 'reacts' to new Twitter events and it's really only an implementation detail that it uses polling to create synthetic 'events': https://www.val.town/v/stevekrouse/twitterAlert. It would be so cool to have abstractions that let folks recompose these triggers more fluidly than what we have now. One thing that comes to mind is middleware. You could imagine a 'stripe webhook middleware' that does this processing so that you can import & wrap you handler to accept pre-processed stripe events I think a good first start in this direction would be to make a series of these 'trigger vals' that only create these synthetic triggers with very comprehensive readmes to explain how to set them up. Then we could have a page that lists all of these. We're also definitely considering Zapier-style triggers that we auto-configure for you via OAuth, but we'll probably need to hire a person or two before we have the bandwidth to experiment in that direction |
Beta Was this translation helpful? Give feedback.
-
An addition to this idea: It would be nice to have a way to trigger vals from the val.town UI. Ex: Adding a custom item to this section, that would create a POST request to one of my val, allowing me to process it however I want. |
Beta Was this translation helpful? Give feedback.
-
I was tinkering with setting up a twilio/sms webhook with valtown (still fighting SMS verification), and was thinking it would be really cool if you could abstract this type of trigger for vals. In brainstoring possible generalized triggers for notification like things (e.g. sms), I have arrived on the idea of a Webhook val. This is in some sense a generalization on Email vals.
Consider email vals, which for the sake of example we will assume are implemented using some sort of webhook with an email service of some sort (for this example, let's say aws SNS/SMS). That means that when you receive an email, aws's mail server notices, and POSTs val town, who then transforms the POST into an interface Email that vals get to see Emails as, and your val is called. The val provides you with the "trigger" for using it, which is an email address. You just implement a function to determine what to do when an
Email
is received, and theEmail
is the input to the function.Now, consider a hypothetical SMS triggered val, implemented with a Webhook val. It also will ("internally" -- it is defined somewhere, but I don't have to think about it) handle receiving messy Twilio POSTs just like we assumed email vals do. It will also have a nice output schema, a ts object, so let's call it an
Interface SMS
for consistency. I will implement a function to determine what to do when anSMS
is received. Since this is a "Webhook" val, Val Town will provide me with a unique Webhook URL. I can give that to twilio, and I'm set. Just like an email val, my function (e.g.webhookValHandler
) will getSMS
object as input.Before continuing, I want to point out that Email vals provide just one output schema, Email, but that doesn't need to hold for Webhook vals. I wanted an analog to email for the SMS example, but note that there's no reason to limit ourselves to a single output. We can have multiple endpoints for our webhook, e.g.
SMS
,Voice
, ...), where our Webhook definition will provide them all to our function as separate arguments.To make your FIRST Webhook val for receiving SMS:
Then I'll also provide a description, which will have step by steps for how to GIVE Twilio the webhooks that will be generated by val town (e.g. A big chunk of text that says "go to homepage, go to phone numbers, ..,..,.. paste webhook into "receive sms" box)
wolf/SMS
is at the top of the list, but ALSO, other people's definitions (if they are public), so, like,johnsmith/Stripe
, orjanedoe/Slack
wolf/SMS
. Just like anemail
val there is a "Copy Webhook" button in the top right of the val. When I click the button, or maybe before, I get a popup with instructions on how to give Twilio that Webhook (defined in 1.).We can also crank this idea further for generalizing triggers. Like. if you guys add websockets, it would be cool if you can make abstractions with a similar format for things like discord bots I think the hardest part of executing this idea is that it requires some sort of "Webhook" center, but I wanted to share it, since I think it enables a lot of possibilities: Webhook discoverability. Github webhooks, or Telegram for example. It would be fun to see the possibilities, AND Reduced friction for generic-ish callbacks.
Beta Was this translation helpful? Give feedback.
All reactions