The Cyberverse
The Cyberverse•10mo ago

GitHub Webhooks not working with HttpAction

Hi, So I've been having this issue with GitHub API and convex, as I want to get an installation id when the user connects to GitHub, how do I get the url for the httpAction to add as a Webhook url for GitHub? Also can someone take a look at my code as this is my first time working with the GitHub api https://github.com/Cyberverse2/squid
GitHub
GitHub - CyberVerse2/squid
Contribute to CyberVerse2/squid development by creating an account on GitHub.
20 Replies
erquhart
erquhart•10mo ago
The url for http actions is https://<your deployment name>.convex.site, plus the route. So if I define a route:
http.route({
path: "/getMessage",
method: "GET",
handler: getMessage,
});
http.route({
path: "/getMessage",
method: "GET",
handler: getMessage,
});
and my deployment name is happy-animal-123 , the url would be:
https://happy-animal-123.convex.site/getMessage
https://happy-animal-123.convex.site/getMessage
erquhart
erquhart•10mo ago
HTTP actions are exposed via convex/http.ts - docs here: https://docs.convex.dev/functions/http-actions#defining-http-actions
HTTP Actions | Convex Developer Hub
HTTP actions allow you to build an HTTP API right in Convex!
The Cyberverse
The CyberverseOP•10mo ago
Ok, so I have to deploy to prod to get a deployment name, right?
erquhart
erquhart•10mo ago
No, all deployments have names, including your dev deployment You can find it in your project settings
The Cyberverse
The CyberverseOP•10mo ago
Mine is blisfull salamander 460, but when I try to navigate to it, the browser just says "webpage not found"
erquhart
erquhart•10mo ago
If you've run npx convex dev successfully after adding your http.ts file with at least one route configured, you can use https://blissful-salamander-460.convex.site/myRoute to access it
The Cyberverse
The CyberverseOP•10mo ago
Ok, if GitHub sends a post request to my httpAction function, would it reflect in my functions dashboard?
erquhart
erquhart•10mo ago
Yep If you're trying to navigate to your deployment in a browser you'll get a 404 If you navigate to a configured route from an http action, however, that will work fine, or it will say "no matching routes found"
The Cyberverse
The CyberverseOP•10mo ago
Ok, also, can I use the fs module in convex
erquhart
erquhart•10mo ago
There's no filesystem to reference in a convex function, they're serverless functions. That said, if you're trying to use fs for something other than interacting with the filesystem, it should load fine if you're using the node environment (I think, haven't actually tried it) (not that there's much you can do with fs outside of interacting with the filesystem)
The Cyberverse
The CyberverseOP•10mo ago
Yeah, the thing is that I have a private key in pem format that I want to use for my octokit, wo I would need to read the data inside using fs.readfile? Is there any other way I can achieve it without using fs?
erquhart
erquhart•10mo ago
Put it in an env var, although you may need to play with the string format to get it to work correctly
The Cyberverse
The CyberverseOP•10mo ago
Ok, I would try that
erquhart
erquhart•10mo ago
I've done it but it's been a while. You'll probably need to take one of the approaches in the top two answers for this SO question, I think the method I used was closer to the accepted answer: https://stackoverflow.com/questions/55459528/using-private-key-in-a-env-file
Stack Overflow
Using private key in a .env file
I have a multiline private key in a gatsby .env file: GATSBY_GOOGLE_CLIENT_ID="12345" GATSBY_GOOGLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nflkdflkdf...\n-----END PRIVATE KEY-----" In my gatsby-
erquhart
erquhart•10mo ago
obviously you'd have to adapt to using an env variable in convex dashboard and not an env file, but this should still apply
The Cyberverse
The CyberverseOP•10mo ago
Oh, thanks @erquhart 🔥 Also, is there no way to view responses from the httpAction request? I've successfully set up GitHub app installation, but I'm getting an error and I don't know what I'm doing wrong unless I see the response
erquhart
erquhart•10mo ago
I believe GitHub surfaces responses if you check out the settings for your GitHub app, cannot recall where that's at though hmm I may be thinking of webhook deliveries, not sure if they do it with Apps Quickest way to get visibility is to console log whatever you want to see from your function body, then check it out in the Convex dashboard logs view
The Cyberverse
The CyberverseOP•10mo ago
Ok, lemme try that
Michal Srb
Michal Srb•10mo ago
The PEM format ignores whitespace, so you can just paste it into the env variable value field and it will work fine. To debug HTTP actions you can log (via consoe.log) the response or anything else and then look the logs in your dashboard (or via npx convex logs).
The Cyberverse
The CyberverseOP•10mo ago
Thanks @Michal Srb

Did you find this page helpful?