···
text: "yes, looks good!",
action_id: "make-account",
···
-
slackApp.action("make-account", async ({ context }) => {
-
await context.respond({
-
response_type: "ephemeral",
-
text: `great! your account has been created :yay:\n\nsign in at <https://waka.hackclub.com/login|hackatime> with your username \`${context.userId}\` and the password you just set up!`,
slackApp.action("bad-info", async ({ context }) => {
···
text: "yes, looks good!",
+
value: password as string,
action_id: "make-account",
···
+
slackApp.action("make-account", async ({ context, payload }) => {
+
if (!context?.respond) return;
+
if (!context.client.users) return;
+
await context.client.users.info({ user: context.userId as string })
+
user.real_name || user.profile?.display_name || "Anonymous Hacker";
+
const password = payload?.actions[0].value;
+
const signup: { created: boolean; api_key: string } = await fetch(
+
"https://waka.hackclub.com/signup",
+
"Content-Type": "application/x-www-form-urlencoded",
+
Authorization: `Bearer ${process.env.HACKATIME_API_KEY}`,
+
body: new URLSearchParams({
+
location: user.tz as string,
+
username: context.userId as string,
+
email: user.profile?.email || "",
+
password: password || "",
+
password_repeat: password || "",
+
).then((res) => res.json());
+
await context.respond({
+
response_type: "ephemeral",
+
text: "great! your account has been created :yay:",
+
text: "great! your account has been created :yay:",
+
text: `you can now log in to the <https://waka.hackclub.com/login|Hackatime dashboard> with your username \`${context.userId}\` and password \`${password}\` :3c:`,
+
text: `your api key for the Hackatime API is \`${signup.api_key}\``,
slackApp.action("bad-info", async ({ context }) => {