diff --git a/action.mjs b/action.mjs
new file mode 100644
index 0000000..0cdb54a
--- /dev/null
+++ b/action.mjs
@@ -0,0 +1,86 @@
+import { readFileSync } from "node:fs";
+
+class CreateListmonkCampaign {
+ constructor() {
+ this.run();
+ }
+
+ async run() {
+ let postNumber = `00000${readFileSync("site/post/count", "utf8")}`.slice(
+ -6
+ );
+ let postData = readFileSync(`site/post/${postNumber}.md`, "utf8");
+
+ let title = postData.slice(postData.indexOf("## ") + 3);
+ title = title.slice(0, title.indexOf("\n"));
+
+ let imageUrl = postData.slice(postData.indexOf("](/") + 3);
+ imageUrl = imageUrl.slice(0, imageUrl.indexOf(")"));
+ imageUrl = `https://xn--trupgrd-exae.com/${imageUrl}`;
+
+ let contentBody = `
+
${title}
+
+
+
+ View Post
+ `;
+
+ let createRequestBody = {
+ name: title,
+ subject: "New Post",
+ lists: [process.env.INPUT_IS_PRODUCTION == "true" ? 3 : 4],
+ from_email: "TårupGård Mailer ",
+ content_type: "html",
+ type: "regular",
+ template_id: 1,
+ body: contentBody,
+ };
+
+ console.log(process.env.INPUT_LISTMONK_USER);
+
+ let requestHeaders = {
+ Authorization:
+ "Basic " +
+ Buffer.from(
+ `${process.env.INPUT_LISTMONK_USER}:${process.env.INPUT_LISTMONK_PASS}`
+ ).toString("base64"),
+ "Content-Type": "application/json;charset=utf-8",
+ };
+
+ let createResponse = await fetch(
+ "https://mailer.tarupgard.com/api/campaigns",
+ {
+ method: "POST",
+ headers: requestHeaders,
+ body: JSON.stringify(createRequestBody),
+ }
+ );
+
+ let campaignId = (await createResponse.json()).data.id;
+
+ await fetch(
+ `https://mailer.tarupgard.com/api/campaigns/${campaignId}/status`,
+ {
+ method: "PUT",
+ headers: requestHeaders,
+ body: JSON.stringify({
+ status: "running",
+ }),
+ }
+ );
+ }
+}
+
+new CreateListmonkCampaign();
+
+// COMMIT_MESSAGE="$(git log)"
+// if [[ $COMMIT_MESSAGE == *"__post__"* ]]; then
+// [[ ${COMMIT_MESSAGE} =~ __post__([[:digit:]]{6}) ]] && POST_NUMBER=${BASH_REMATCH[1]}
+
+// echo $POST_NUMBER
+// TITLE=$(cat site/post/$POST_NUMBER.md | grep "\#\#\ ")
+// TITLE=${TITLE:3}
+// IMAGE_URL=https://xn--trupgrd-exae.com/$(cat site/post/$POST_NUMBER.md | grep "_01.jpg" | grep -oP '(?<=\]\().*?(?=\))')
+// # curl -u "$INPUT_LISTMONK_USER:$INPUT_LISTMONK_PASS" -X GET 'https://mailer.tarupgard.com/api/campaigns?page=1&per_page=100'
+// fi
diff --git a/action.sh b/action.sh
deleted file mode 100755
index 09db8c9..0000000
--- a/action.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-
-COMMIT_MESSAGE="$(git log)"
-if [[ $COMMIT_MESSAGE == *"__post__"* ]]; then
- [[ ${COMMIT_MESSAGE} =~ __post__([[:digit:]]{6}) ]] && POST_NUMBER=${BASH_REMATCH[1]}
- echo $POST_NUMBER
- # curl -u "$INPUT_LISTMONK_USER:$INPUT_LISTMONK_PASS" -X GET 'https://mailer.tarupgard.com/api/campaigns?page=1&per_page=100'
-fi
-
diff --git a/action.yaml b/action.yaml
index 8defcab..69cd611 100644
--- a/action.yaml
+++ b/action.yaml
@@ -8,8 +8,13 @@ inputs:
listmonk_pass:
description: Password for interacting with listmonk
required: true
+ is_production:
+ description: flag that the update should be sent to actual users
+ required: true
runs:
using: "composite"
steps:
- - run: $GITHUB_ACTION_PATH/action.sh
- shell: bash
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 18
+ - run: node action.js