Created
January 16, 2025 13:33
-
-
Save asukaminato0721/60ef4e9abb938572c0cfb68dcbf10a23 to your computer and use it in GitHub Desktop.
xuanwo_keywords_bot source code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@ts-check | |
export default { | |
async fetch(request, env) { | |
try { | |
if (request.method !== 'POST') { | |
return new Response('Method not allowed', { status: 405 }); | |
} | |
const { message } = await request.json(); | |
if (!message?.text) { | |
return new Response('OK', { status: 200 }); | |
} | |
const chatId = message.chat.id; | |
const text = message.text; | |
if (["s3", 'fs', '存储'].some(key => text.includes(key))) { | |
await handleXuanwoCommand(text, chatId, env.TELEGRAM_BOT_TOKEN); | |
} | |
return new Response('OK', { status: 200 }); | |
} catch (error) { | |
console.error('Error:', error); | |
return new Response('Internal Server Error', { status: 500 }); | |
} | |
} | |
}; | |
async function handleXuanwoCommand(formula, chatId, botToken) { | |
try { | |
const formData = new FormData(); | |
formData.append('chat_id', chatId); | |
formData.append('text', "@xuanwo 有活了"); | |
await fetch(`https://api.telegram.org/bot${botToken}/sendMessage`, { | |
method: 'POST', | |
body: formData | |
}); | |
} catch (error) { | |
console.error('Error sending ', error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment