use crate::Result;
use crate::types::update::{
AnswerCallbackQueryRequest, AnswerInlineQueryRequest, GetUpdatesRequest, Update,
};
use crate::types::upload::UploadFile;
use crate::types::webhook::{DeleteWebhookRequest, SetWebhookRequest, WebhookInfo};
#[cfg(feature = "_blocking")]
use crate::BlockingClient;
#[cfg(feature = "_async")]
use crate::Client;
#[cfg(feature = "_async")]
#[derive(Clone)]
pub struct UpdatesService {
client: Client,
}
#[cfg(feature = "_async")]
impl UpdatesService {
pub(crate) fn new(client: Client) -> Self {
Self { client }
}
pub async fn get_updates(&self, request: &GetUpdatesRequest) -> Result<Vec<Update>> {
self.client.call_method("getUpdates", request).await
}
pub async fn set_webhook(&self, request: &SetWebhookRequest) -> Result<bool> {
self.client.call_method("setWebhook", request).await
}
pub async fn set_webhook_with_certificate(
&self,
request: &SetWebhookRequest,
certificate: &UploadFile,
) -> Result<bool> {
self.client
.call_method_multipart("setWebhook", request, "certificate", certificate)
.await
}
pub async fn delete_webhook(&self, request: &DeleteWebhookRequest) -> Result<bool> {
self.client.call_method("deleteWebhook", request).await
}
pub async fn get_webhook_info(&self) -> Result<WebhookInfo> {
self.client.call_method_no_params("getWebhookInfo").await
}
pub async fn answer_callback_query(
&self,
request: &AnswerCallbackQueryRequest,
) -> Result<bool> {
self.client
.call_method("answerCallbackQuery", request)
.await
}
pub async fn answer_inline_query(&self, request: &AnswerInlineQueryRequest) -> Result<bool> {
self.client.call_method("answerInlineQuery", request).await
}
}
#[cfg(feature = "_blocking")]
#[derive(Clone)]
pub struct BlockingUpdatesService {
client: BlockingClient,
}
#[cfg(feature = "_blocking")]
impl BlockingUpdatesService {
pub(crate) fn new(client: BlockingClient) -> Self {
Self { client }
}
pub fn get_updates(&self, request: &GetUpdatesRequest) -> Result<Vec<Update>> {
self.client.call_method("getUpdates", request)
}
pub fn set_webhook(&self, request: &SetWebhookRequest) -> Result<bool> {
self.client.call_method("setWebhook", request)
}
pub fn set_webhook_with_certificate(
&self,
request: &SetWebhookRequest,
certificate: &UploadFile,
) -> Result<bool> {
self.client
.call_method_multipart("setWebhook", request, "certificate", certificate)
}
pub fn delete_webhook(&self, request: &DeleteWebhookRequest) -> Result<bool> {
self.client.call_method("deleteWebhook", request)
}
pub fn get_webhook_info(&self) -> Result<WebhookInfo> {
self.client.call_method_no_params("getWebhookInfo")
}
pub fn answer_callback_query(&self, request: &AnswerCallbackQueryRequest) -> Result<bool> {
self.client.call_method("answerCallbackQuery", request)
}
pub fn answer_inline_query(&self, request: &AnswerInlineQueryRequest) -> Result<bool> {
self.client.call_method("answerInlineQuery", request)
}
}