-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support Telegram Bot API 7.7
- Loading branch information
1 parent
988c03e
commit 27cd931
Showing
10 changed files
with
162 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,4 +173,5 @@ dist | |
|
||
# Finder (MacOS) folder config | ||
.DS_Store | ||
tg-bot-api | ||
tg-bot-api | ||
test.ts |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { inspectable } from "inspectable"; | ||
|
||
import type { TelegramObjects } from "@gramio/types"; | ||
import { Message } from "../structures/index"; | ||
|
||
import type { Constructor } from "../types"; | ||
import { applyMixins, memoizeGetters } from "../utils"; | ||
|
||
import { RefundedPayment } from "../structures/refunded-payment"; | ||
import type { BotLike } from "../types"; | ||
import { Context } from "./context"; | ||
import { | ||
ChatActionMixin, | ||
CloneMixin, | ||
NodeMixin, | ||
PinsMixin, | ||
SendMixin, | ||
TargetMixin, | ||
} from "./mixins/index"; | ||
|
||
interface RefundedPaymentContextOptions<Bot extends BotLike> { | ||
bot: Bot; | ||
update: TelegramObjects.TelegramUpdate; | ||
payload: TelegramObjects.TelegramMessage; | ||
updateId: number; | ||
} | ||
|
||
/** | ||
* This object contains basic information about a successful payment. | ||
* | ||
* [Documentation](https://core.telegram.org/bots/api/#RefundedPayment) | ||
*/ | ||
class RefundedPaymentContext<Bot extends BotLike> extends Context<Bot> { | ||
/** The raw data that is used for this Context */ | ||
payload: TelegramObjects.TelegramMessage; | ||
|
||
constructor(options: RefundedPaymentContextOptions<Bot>) { | ||
super({ | ||
bot: options.bot, | ||
updateType: "refunded_payment", | ||
updateId: options.updateId, | ||
update: options.update, | ||
}); | ||
|
||
this.payload = options.payload; | ||
} | ||
|
||
/** Received payment */ | ||
get eventPayment() { | ||
return new RefundedPayment( | ||
this.payload.refunded_payment as TelegramObjects.TelegramRefundedPayment, | ||
); | ||
} | ||
} | ||
|
||
interface RefundedPaymentContext<Bot extends BotLike> | ||
extends Constructor<RefundedPaymentContext<Bot>>, | ||
Message, | ||
TargetMixin, | ||
SendMixin<Bot>, | ||
ChatActionMixin<Bot>, | ||
NodeMixin<Bot>, | ||
PinsMixin<Bot>, | ||
CloneMixin< | ||
Bot, | ||
RefundedPaymentContext<Bot>, | ||
RefundedPaymentContextOptions<Bot> | ||
> {} | ||
applyMixins(RefundedPaymentContext, [ | ||
Message, | ||
TargetMixin, | ||
SendMixin, | ||
ChatActionMixin, | ||
NodeMixin, | ||
PinsMixin, | ||
CloneMixin, | ||
]); | ||
memoizeGetters(RefundedPaymentContext, ["eventPayment"]); | ||
|
||
inspectable(RefundedPaymentContext, { | ||
serialize(context) { | ||
return { | ||
id: context.id, | ||
from: context.from, | ||
senderId: context.senderId, | ||
createdAt: context.createdAt, | ||
chat: context.chat, | ||
chatId: context.chatId, | ||
chatType: context.chatType, | ||
eventPayment: context.eventPayment, | ||
}; | ||
}, | ||
}); | ||
|
||
export { RefundedPaymentContext }; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import type { TelegramObjects } from "@gramio/types"; | ||
import { Inspect, Inspectable } from "inspectable"; | ||
|
||
/** | ||
* This object contains basic information about a refunded payment. | ||
* | ||
* [Documentation](https://core.telegram.org/bots/api/#refundedpayment) | ||
*/ | ||
@Inspectable() | ||
export class RefundedPayment { | ||
constructor(public payload: TelegramObjects.TelegramRefundedPayment) {} | ||
|
||
get [Symbol.toStringTag]() { | ||
return this.constructor.name; | ||
} | ||
|
||
/** | ||
* Three-letter ISO 4217 [currency](https://core.telegram.org/bots/payments#supported-currencies) code, or “XTR” for payments in [Telegram Stars](https://t.me/BotNews/90). Currently, always “XTR” | ||
*/ | ||
@Inspect() | ||
get currency() { | ||
return this.payload.currency; | ||
} | ||
|
||
/** | ||
* Total refunded price in the *smallest units* of the currency (integer, **not** float/double). For example, for a price of `US$ 1.45`, `total_amount = 145`. See the *exp* parameter in [currencies.json](https://core.telegram.org/bots/payments/currencies.json), it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). | ||
*/ | ||
@Inspect() | ||
get totalAmount() { | ||
return this.payload.total_amount; | ||
} | ||
|
||
/** | ||
* Bot-specified invoice payload | ||
*/ | ||
@Inspect() | ||
get invoicePayload() { | ||
return this.payload.invoice_payload; | ||
} | ||
|
||
/** | ||
* Telegram payment identifier | ||
*/ | ||
@Inspect() | ||
get telegramPaymentChargeId() { | ||
return this.payload.telegram_payment_charge_id; | ||
} | ||
|
||
/** | ||
* *Optional*. Provider payment identifier | ||
*/ | ||
@Inspect() | ||
get providerPaymentChargeId() { | ||
return this.payload.provider_payment_charge_id; | ||
} | ||
} |
This file contains 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