|
|
@@ -0,0 +1,34 @@
|
|
|
+import { Context } from "grammy";
|
|
|
+
|
|
|
+export interface Env {
|
|
|
+ BOT_INFO: string;
|
|
|
+ BOT_TOKEN: string;
|
|
|
+ COSMOE_CREDENTIALS: KVNamespace;
|
|
|
+ COSMOE_STORAGE: KVNamespace;
|
|
|
+}
|
|
|
+
|
|
|
+export async function handleLogoutCommand(ctx: Context, env: Env): Promise<void> {
|
|
|
+ try {
|
|
|
+ // Get user ID from context
|
|
|
+ const userId = ctx.from?.id;
|
|
|
+ if (!userId) {
|
|
|
+ await ctx.reply("❌ Unable to identify your account. Please try again.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Check if credentials exist for this user
|
|
|
+ const credentials = await env.COSMOE_CREDENTIALS.get(userId.toString());
|
|
|
+ if (!credentials) {
|
|
|
+ await ctx.reply("⚠️ You are not logged in. No credentials to clear.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Delete the stored credentials
|
|
|
+ await env.COSMOE_CREDENTIALS.delete(userId.toString());
|
|
|
+
|
|
|
+ await ctx.reply("✅ Successfully logged out. Your account information has been cleared from our system.");
|
|
|
+ } catch (error) {
|
|
|
+ console.error("Error handling logout request:", error);
|
|
|
+ await ctx.reply("❌ An error occurred while logging out. Please try again.");
|
|
|
+ }
|
|
|
+}
|