Foile / crypto-pay-api

Cryptocurrency payment system based on @CryptoBot
MIT License
79 stars 17 forks source link

Can't use webhooks on Heroku #2

Closed Matvert closed 2 years ago

Matvert commented 2 years ago

I am hosting my bot on heroku and cannot use webhooks with your library because of heroku limitations. It would be very useful to be able to mount webhooks to an existing http server.

Foile commented 2 years ago

You can use API and webhooks separately.

Monolith way:

const cryptoPay = new CryptoPay(token, {
  hostname: 'testnet-pay.crypt.bot',
  webhook: { serverHostname: '0.0.0.0', serverPort: process.env.PORT, path: '/secret-path' }
})

// API method
cryptoPay.getMe().then(app => console.log(app))

// Webhook update
cryptoPay.invoicePaid(update => console.log(update.payload))

Separate work:

const cryptoPay = new CryptoPay(token, { hostname: 'testnet-pay.crypt.bot' })

// API method
cryptoPay.getMe().then(app => console.log(app))
const cryptoPay = new CryptoPay(token, {
  webhook: { serverHostname: '0.0.0.0', serverPort: process.env.PORT, path: '/secret-path' }
})

// Webhook update
cryptoPay.invoicePaid(update => console.log(update.payload))