I'm a beginner with javascript/web development. But I'm trying to do a Slack bot which uses Github API. I would like to post a message on Slack when a Github release is created. I use Octokit library to request my URL.
const octokit = new Octokit({ auth: process.env.GITHUB_AUTH });
const getReleaseTrigger = async function () {
const res = await octokit.request('POST /payload', {
});
const resJSON = JSON.parse(res);
return resJSON
};
(async () => {
await app.start(process.env.PORT || 3000);
try {
const releaseTrigger = await getReleaseTrigger();
const slackBodyGithubMessage = {
mkdwn: true,
text: `*${releaseInfo}*`
}
const res = await request({
url: `https://hooks.slack.com/services/${hookPersonalMessages}`,
method: 'POST',
body: slackBodyGithubMessage,
json: true
})
} catch (e) {
console.log('our error', e);
} debugger;
console.log('Slack app is running!');
})();
It's strange cause, my console respond this when I launch my app :
our error RequestError [HttpError]: Not Found
at /home/mai-ly/Bureau/slack-bot/testGitIgnore/slack-bot-skillz/node_modules/@octokit/request/dist-node/index.js:86:21
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async getReleaseTrigger (/home/mai-ly/Bureau/slack-bot/testGitIgnore/slack-bot-skillz/app.js:139:15)
at async /home/mai-ly/Bureau/slack-bot/testGitIgnore/slack-bot-skillz/app.js:149:28 {
status: 404,
response: {
url: 'https://api.github.com/payload',
status: 404,
headers: {
'access-control-allow-origin': '*',
'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset',
connection: 'close',
[....]
BUT my console Ngrok detect when I create a new release on my repo : screenshot Ngrok
It send me a "good" response (despite the 404 error displayed), with a good ref/title (in this case : test21, this is the title I put on the release on github) with ngrok console. Futhermore, my local console write 5 times this sentence : " [INFO] Unhandled HTTP request (POST) made to /payload "
It seems to detect my repo, and react well when I create a new release. But I can't access the answer in my Slack message. And the 404 error seems strange to me. And I don't understand why it notice me 5 times for each release created.
I would like to get the title and the description of the release just created. Do you have any idea how to do this?
Thanks a lot for your future response
Have a good day
Juan Pablo Isaza