Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ entries. You can also delete entries from this screen. If you are wanting to
stop using Jotbot you can delete your account using /delete_account this will
also delete all of your journal entries!

## Configuration

The bot can be configured using environment variables in a `.env` file:

- `TELEGRAM_BOT_KEY`: Your Telegram bot token (required)
- `TELEGRAM_API_BASE_URL`: Custom Telegram Bot API base URL (optional, defaults
to `https://api.telegram.org`)

## Commands

**/start** - Start the bot, if it's your first time messaging the bot you will
Expand Down
Binary file removed assets/404/1680564645_404.jpg
Binary file not shown.
1 change: 0 additions & 1 deletion constants/numbers.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export const pdfFontSize = 30;
export const MAX_FILE_SIZE_BYTES = 10 * 1024 * 1024; // 10MB limit for file uploads
53 changes: 15 additions & 38 deletions constants/strings.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
export const startString: string =
`Hello! Welcome to JotBot. I'm here to help you record your emotions and emotion!`;
// This will be constructed dynamically using the configured API base URL
export const getTelegramDownloadUrl = (
baseUrl: string,
token: string,
filePath: string,
) => `${baseUrl}/file/bot${token}/${filePath}`;
export const telegramDownloadUrl =
"https://api.telegram.org/file/bot<token>/<file_path>";

export const catImagesApiBaseUrl = `https://cataas.com`;
export const quotesApiBaseUrl = `https://zenquotes.io/api/quotes/`;
Expand Down Expand Up @@ -41,41 +37,22 @@ export const helpString: string = `
Jotbot is a telegram bot that can help you to record your thoughts and emotions in directly in the telegram app.

<b><u>How do I use Jotbot?</u></b>
Jotbot is easy to use you have to be "registered" to start recording entries.
Once this is done you can use /new_entry to start recording an entry. You just answer the bot's questions to the best of you ability from there.

<b>🚀 Getting Started:</b>
• Send /start to begin registration
• Follow the prompts to create your profile

<b>📝 Creating Entries:</b>
• Use /new_entry to start a new journal entry
• Answer 4 simple questions about your thoughts and emotions
• Each step is clearly labeled with examples

<b>👀 Viewing Entries:</b>
• Use /view_entries to browse your journal
• Navigate with Previous/Next buttons
• Edit or delete entries as needed

<b>⚙️ Settings:</b>
• Use /settings to customize your experience
• Toggle mental health score saving
• Set a custom 404 image for entries without photos

<b>🆘 Need Help?</b>
• Use /delete_account to remove all your data
After you are finished recording your entry you can view your entry by using /view_entries. This will bring up a menu that let's you scroll through your entries. You can also delete entries from this screen.
If you are wanting to stop using Jotbot you can delete your account using /delete_account this will also delete all of your journal entries!

<b><u>Commands</u></b>
/start - Register or access your account
/help - Show this help message
/new_entry - Create a new journal entry (4 simple steps)
/view_entries - Browse and manage your entries
/settings - Customize your bot experience
/kitties - View cute cats for stress relief
/am_i_depressed - Take a depression assessment (PHQ-9)
/am_i_anxious - Take an anxiety assessment (GAD-7)
/snapshot - View your mental health summary
/delete_account - Permanently delete all your data
/🆘 or /sos - Access crisis support resources
/start - Start the bot, if it's your first time messaging the bot you will be asked if you want to register.
/help - Prints this help string in a message
/new_entry - Start a new entry
/view_entries - Scroll through your entries
/kitties - Open the kitties app! Studies show kitties can help with depression
/delete_account - Delete your accound plus all entries
/🆘 or /sos - Show the crisis help lines

<b>NOTE</b>: The selfie features aren't working right now.
`;

export enum Emotions {
Expand Down
39 changes: 8 additions & 31 deletions db/migration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { PathLike } from "node:fs";
import { DatabaseSync } from "node:sqlite";
import { sqlFilePath } from "../constants/paths.ts";
import { logger } from "../utils/logger.ts";

export function createEntryTable(dbFile: PathLike) {
try {
Expand All @@ -12,7 +11,7 @@ export function createEntryTable(dbFile: PathLike) {
db.prepare(query).run();
db.close();
} catch (err) {
logger.error(`Failed to create entry_db table: ${err}`);
console.error(`Failed to create entry_db table: ${err}`);
}
}

Expand All @@ -26,7 +25,7 @@ export function createGadScoreTable(dbFile: PathLike) {
db.prepare(query).run();
db.close();
} catch (err) {
logger.error(`Failed to create gad_score_db table: ${err}`);
console.error(`There was a a problem create the user_db table: ${err}`);
}
}

Expand All @@ -40,7 +39,7 @@ export function createPhqScoreTable(dbFile: PathLike) {
db.prepare(query).run();
db.close();
} catch (err) {
logger.error(`Failed to create phq_score_db table: ${err}`);
console.error(`There was a a problem create the user_db table: ${err}`);
}
}

Expand All @@ -54,7 +53,7 @@ export function createUserTable(dbFile: PathLike) {
db.prepare(query).run();
db.close();
} catch (err) {
logger.error(`Failed to create user_db table: ${err}`);
console.error(`There was a a problem create the user_db table: ${err}`);
}
}

Expand All @@ -68,7 +67,7 @@ export function createSettingsTable(dbFile: PathLike) {
db.prepare(query).run();
db.close();
} catch (err) {
logger.error(`Failed to create settings_db table: ${err}`);
console.error(`Failed to create settings table: ${err}`);
}
}

Expand All @@ -82,7 +81,7 @@ export function createJournalTable(dbFile: PathLike) {
db.prepare(query).run();
db.close();
} catch (err) {
logger.error(`Failed to create journal_db table: ${err}`);
console.error(`Failed to create settings table: ${err}`);
}
}

Expand All @@ -95,7 +94,7 @@ export function createJournalEntryPhotosTable(dbFile: PathLike) {
db.prepare(query).run();
db.close();
} catch (err) {
logger.error(`Failed to create photo_db table: ${err}`);
console.error(`Failed to create settings table: ${err}`);
}
}

Expand All @@ -109,28 +108,6 @@ export function createVoiceRecordingTable(dbFile: PathLike) {
db.prepare(query).run();
db.close();
} catch (err) {
logger.error(`Failed to create voice_recording_db table: ${err}`);
}
}

export function addCustom404Column(dbFile: PathLike) {
try {
const db = new DatabaseSync(dbFile);
db.exec("PRAGMA foreign_keys = ON;");
// Check if column exists to avoid errors
const columns = db.prepare("PRAGMA table_info(settings_db);").all() as {
name: string;
}[];
const hasColumn = columns.some((col) => col.name === "custom404ImagePath");
if (!hasColumn) {
db.prepare(`
ALTER TABLE settings_db
ADD COLUMN custom404ImagePath TEXT DEFAULT NULL;
`).run();
logger.info("Added custom404ImagePath column to settings_db");
}
db.close();
} catch (err) {
logger.error(`Failed to add custom404ImagePath column: ${err}`);
console.error(`Failed to create settings table: ${err}`);
}
}
1 change: 0 additions & 1 deletion db/sql/create_settings_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ CREATE TABLE IF NOT EXISTS settings_db (
id INTEGER PRIMARY KEY AUTOINCREMENT,
userId INTEGER,
storeMentalHealthInfo INTEGER DEFAULT 0,
custom404ImagePath TEXT DEFAULT NULL,
FOREIGN KEY (userId) REFERENCES user_db(telegramId) ON DELETE CASCADE
);
2 changes: 1 addition & 1 deletion db/sql/misc/get_latest_entry_id.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SELECT MAX(id) as max_id FROM <TABLE_NAME>;
SELECT seq FROM sqlite_sequence WHERE name='<TABLE_NAME>';
3 changes: 1 addition & 2 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
},
"imports": {
"@grammyjs/commands": "npm:@grammyjs/commands@^1.2.0",
"@grammyjs/conversations": "npm:@grammyjs/conversations@^1.1.1",
"@grammyjs/conversations": "npm:@grammyjs/conversations@^2.1.1",
"@grammyjs/files": "npm:@grammyjs/files@^1.2.0",
"@std/assert": "jsr:@std/assert@^1.0.16",
"@std/log": "jsr:@std/log@^0.224.14",
"grammy": "npm:grammy@^1.38.4"
}
}
33 changes: 0 additions & 33 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 5 additions & 10 deletions handlers/delete_account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ import { Conversation } from "@grammyjs/conversations";
import { deleteAccountConfirmKeyboard } from "../utils/keyboards.ts";
import { deleteUser } from "../models/user.ts";
import { dbFile } from "../constants/paths.ts";
import { logger } from "../utils/logger.ts";

export async function delete_account(conversation: Conversation, ctx: Context) {
if (!ctx.from) {
await ctx.reply("Error: Unable to identify user.");
return;
}
try {
await ctx.reply(
`⚠️ Are you sure you want to <b><u>delete</u></b> your account <b>along with all of your data</b>? ⚠️`,
Expand All @@ -22,21 +17,21 @@ export async function delete_account(conversation: Conversation, ctx: Context) {
]);

if (deleteAccountCtx.callbackQuery.data === "delete-account-yes") {
await conversation.external(() => deleteUser(ctx.from.id, dbFile));
await conversation.external(() => deleteUser(ctx.from?.id!, dbFile));
} else if (deleteAccountCtx.callbackQuery.data === "delete-account-no") {
conversation.halt();
return await deleteAccountCtx.editMessageText("No changes made!");
}
await conversation.halt();
return await ctx.editMessageText(
`Okay ${ctx.from.username} your account has been terminated along with all of your entries. Thanks for trying Jotbot!`,
`Okay ${ctx.from?.username} your account has been terminated along with all of your entries. Thanks for trying Jotbot!`,
);
} catch (err) {
logger.error(
`Failed to delete user ${ctx.from.username}: ${err}`,
console.log(
`Failed to delete user ${ctx.from?.username}: ${err}`,
);
return await ctx.editMessageText(
`Failed to delete user ${ctx.from.username}: ${err}`,
`Failed to delete user ${ctx.from?.username}: ${err}`,
);
}
}
Loading
Loading