Skip to content

Commit

Permalink
feat: lambda sends request to github action
Browse files Browse the repository at this point in the history
  • Loading branch information
gtempus committed Oct 31, 2023
1 parent 5d902f2 commit ad89f4c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions minecraft-slack-bot/minecraftBot.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const { parse } = require('querystring');
const AWS = require('aws-sdk');
const axios = require('axios');

const secretsManager = new AWS.SecretsManager();

exports.handler = async (event) => {
console.log("Received event:", JSON.stringify(event, null, 2));
Expand All @@ -15,6 +19,40 @@ exports.handler = async (event) => {
const body = parse(event.body);
console.log("Parsed body:", body);

// kick off the github action
// Retrieve GitHub Token from AWS Secrets Manager
const secretData = await secretsManager.getSecretValue({ SecretId: 'github_token' }).promise();
const githubToken = JSON.parse(secretData.SecretString).GITHUB_TOKEN;

// Define the GitHub API endpoint URL
const githubApiUrl = 'https://api.github.com/repos/gtempus/minecraft-terraform/actions/workflows/WORKFLOW_NAME.yml/dispatches';
const data = JSON.stringify({
"event_type": "custom_event",
"client_payload": {
"action": "stop"
}
});
const config = {
method: 'post',
maxBodyLength: Infinity,
url: githubApiUrl,
headers: {
'Accept': 'application/vnd.github.everest-preview+json',
'Content-Type': 'application/json',
'Authorization': `Bearer ${githubToken}`
},
data: data,
};
// Make an HTTP POST request to trigger the GitHub Action
const response = await axios.request(config);

console.log({ response });

// return {
// statusCode: response.status,
// body: JSON.stringify(response.data),
// };

const text = body.text || '';
const responseMessage = `You said: ${text}`;

Expand Down

0 comments on commit ad89f4c

Please sign in to comment.