@darkwolf/telegram-bot.lazy.cjs
Version:
Telegram Bot API
46 lines (39 loc) • 981 B
JavaScript
const Helper = require('@darkwolf/helper.cjs')
const types = require('./')
class ShippingOption {
constructor(id, title, prices) {
this
.setId(id)
.setTitle(title)
.setPrices(prices)
}
setId(id) {
this.id = id
return this
}
setTitle(title) {
this.title = title
return this
}
setPrices(prices) {
this.prices = prices ? prices.map(price =>
price instanceof types.LabeledPrice ? price : new types.LabeledPrice(price.label, price.amount)
) : undefined
return this
}
toParams() {
const params = {}
if (this.id) {
params.id = this.id
}
if (Helper.exists(this.title)) {
params.title = this.title
}
if (this.prices) {
params.prices = this.prices.map(price => price.toParams())
}
return params
}
}
ShippingOption.from = (id, title, prices) => new ShippingOption(id, title, prices)
module.exports = ShippingOption