1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| import { Bot, InlineKeyboard} from "https://deno.land/x/grammy@v1.25.0/mod.ts"; const botToken = "";
const bot = new Bot(botToken);
const providerToken = "";
bot.command("start", async (ctx) => { try { const title = "测试产品"; const description = "这是一个测试产品"; const payload = "test_payload"; const startParameter = "test_start"; const currency = "USD"; const prices = [ { label: "测试产品", amount: 100, currency: currency } ]; const photoUrl = "https://api.telegram.org/file/botYOUR_BOT_TOKEN/photos/file_0.jpg";
const payloadData = { chat_id: ctx.chat.id, title: title, description: description, payload: payload, provider_token: providerToken, start_parameter: startParameter, currency: currency, prices: prices, photo_url: photoUrl, need_shipping_address: false, is_flexible: false, send_phone_number_to_provider: true, send_email_to_provider: true };
const response = await fetch(`https://api.telegram.org/bot${botToken}/sendInvoice`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payloadData) });
const data = await response.json(); if (!data.ok) { throw new Error(`${data.error_code}: ${data.description}`); }
console.log("发票发送成功:", data); } catch (error) { console.error("发送发票时出错:", error.message); await ctx.reply("创建发票失败,请重试。"); } });
bot.on("pre_checkout_query", async (ctx) => { await ctx.answerPreCheckoutQuery(true); });
bot.on("message", async (ctx) => { if (ctx.message.successful_payment) { console.log("支付成功!", ctx.message.successful_payment); await ctx.reply("支付成功!感谢您的购买。"); } });
bot.start();
|