guru
guru3y ago

Webhooks

@ballingt - Any webhook feature on the roadmap?
10 Replies
ballingt
ballingt3y ago
Could you say more? This might mean "every time a query updates, send an HTTP request to a url," but I'm guessing, there are a few other ways webhooks could be relevant.
guru
guruOP3y ago
For the server to send call-back notifications to the web-app.? I meant call back, sorry for the confusion
ballingt
ballingt3y ago
The main way this works is a websocket: a ConvexReactClient instance in the browser has a websocket that receives messages, and from there you describe what you want to happen when queries update.
guru
guruOP3y ago
Does that mean useCallback("....") hook? or using query?
ballingt
ballingt3y ago
In React it's a useQuery hook: that hook causes the React component to rerender each time a query updates. If you're not using React the API is a little different, but the idea is always that you subscribe to a query function, and whenever it changes it runs your callback. Here's a bit in the tutorial that talks about this: https://docs.convex.dev/how-it-works#hooking-up-react-components
guru
guruOP3y ago
That is great! Also coming back to the webhook question, can the back-end interact with a client other than the web page which is creating the state
ballingt
ballingt3y ago
Other users on the same webpage, other web pages subscribed to the same query, and even node server or Python clients or command line tools can use the same queries and mutations. The HTTP API is useful for asking for the current value of a query, or a websocket can be used from node to get updates.
guru
guruOP3y ago
So, what about a classic trigger use case, where I send a notification through SMS using Webhook Do we need to write a node express API to encapsulate the webHook?
ballingt
ballingt3y ago
Stay tuned, there are plans for that kind of thing soon! But if you're doing this today, you'd write at node program (doesn't need express, because it won't be receiving HTTP requests) that uses a websocket to listen for query updates and does the SMS sending, or polls once a minute via HTTP api.
ian
ian3y ago
@guru we just launched support to hit Convex from other services via HTTP: https://blog.convex.dev/announcing-convex-0-9-0/
The Convex Blog
Announcing Convex 0.9.0
HTTP endpoints are here! Convex 0.9.0 extends the platform by allowing you to build your HTTP API right within Convex.

Did you find this page helpful?