You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i have being building a telegram bot with nodejs where people can send in a url of a tweet and if it contains a media of type video. it downloads it and sends it to the user. Thats the purpose, which i already completed.
The problem i have is with setting a paywall on this bot account so that after 2 or 3 request, the user interacting with the bot have to make a payment to continue.
FYI, i'm not using any external librarys, i'm directly interacting with the telegram api endpoints.
I'm using stripe for payments in test mode (my acc is unverified if that helps). the problem i have is as you can see in this picture:
After i send the invoice, then the user clicks the pay button and adds all the necessary card details then after hitting the pay. it keeps buffering and then time outs.
I also tried the createInvoiceLink method and the same thing happened.
Ofcourse its some mistake in my solution, but i dont know where that is. May be i have to use a webhook or something to catch the checkout initiation/completion. but how can i let the Telegram api know about my payment webhook path (assuming something like that exists).
The only one i found is the method setWebhook which is an alternative approach for polling. And that is what i am doing locally with ngrok.
A Part of my code, this is an abstract version of the functionality:
constapp=express();constport=3000;constbotToken=process.env.TELEGRAM_BOT_TOKEN;app.use(bodyParser.json());// Webhook endpoint that receives incoming messages (exposed via ngrok)app.post(`/bot${botToken}`,async(req,res)=>{const{ message }=req.body;console.log({ message });if(message&&message.text){constchatId=message.chat.id;constmessageText=message.text;// after successfull 3 responses from the bot, send an invoiceconstinvoiceRes=awaitsendInvoice(chatId,"Premium Subscription","Unlock premium content with a subscription.","premium_subscription",process.env.PROVIDER_TOKEN,"subscription","USD",[{label: "Subscription",amount: 1000}],);console.log(JSON.stringify(invoiceRes,null,2));}res.status(200).end();});asyncfunctionsendInvoice(chatId,title,description,payload,providerToken,startParameter,currency,prices,){constapiUrl=`https://api.telegram.org/bot${botToken}/sendInvoice`;constinvoice={chat_id: chatId,title: title,description: description,payload: payload,provider_token: providerToken,start_parameter: startParameter,currency: currency,prices: prices,};try{constresponse=awaitfetch(apiUrl,{method: "POST",headers: {"Content-Type": "application/json",},body: JSON.stringify(invoice),});constdata=awaitresponse.json();// console.log(data);returndata;}catch(error){console.error("There was a problem sending the invoice:",error);returnerror.message;}}
I googled a lot to find some answers, there isnt anything specified in the payment section of the docs either rather than getting the provider token (not anything specifically if i have to do on the stripe account dashboard like adding a webhook endpoint, even if that was the case how would telegram know that is the webhook it should communicate too)
I have been mentioning webhook a lot, because in my mind i am assuming that is my missing solution. if it isnt i'm sorry for doing so. I don't have much experience with stripe or building a telegram bot.
I hope i could get some help with this problem. even a small guidance will be enough if you are busy. just something i can go with that's all i ask.
i have being building a telegram bot with nodejs where people can send in a url of a tweet and if it contains a media of type video. it downloads it and sends it to the user. Thats the purpose, which i already completed.
The problem i have is with setting a paywall on this bot account so that after 2 or 3 request, the user interacting with the bot have to make a payment to continue.
so i used the sendInvoice method.
FYI, i'm not using any external librarys, i'm directly interacting with the telegram api endpoints.
I'm using stripe for payments in test mode (my acc is unverified if that helps). the problem i have is as you can see in this picture:
After i send the invoice, then the user clicks the pay button and adds all the necessary card details then after hitting the pay. it keeps buffering and then time outs.
I also tried the createInvoiceLink method and the same thing happened.
Ofcourse its some mistake in my solution, but i dont know where that is. May be i have to use a webhook or something to catch the checkout initiation/completion. but how can i let the Telegram api know about my payment webhook path (assuming something like that exists).
The only one i found is the method setWebhook which is an alternative approach for polling. And that is what i am doing locally with ngrok.
A Part of my code, this is an abstract version of the functionality:
I googled a lot to find some answers, there isnt anything specified in the payment section of the docs either rather than getting the provider token (not anything specifically if i have to do on the stripe account dashboard like adding a webhook endpoint, even if that was the case how would telegram know that is the webhook it should communicate too)
I have been mentioning webhook a lot, because in my mind i am assuming that is my missing solution. if it isnt i'm sorry for doing so. I don't have much experience with stripe or building a telegram bot.
I hope i could get some help with this problem. even a small guidance will be enough if you are busy. just something i can go with that's all i ask.
https://stackoverflow.com/questions/78251916/stripe-pre-checkout-timeout-error-while-making-a-test-payment-from-telegram-bot
The text was updated successfully, but these errors were encountered: