mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Merge branch 'dev' of https://github.com/async-telegram-bot/async-telegram-bot into dev
This commit is contained in:
commit
5296a74e65
3 changed files with 382 additions and 26 deletions
|
@ -1,7 +1,142 @@
|
||||||
use crate::core::requests::RequestContext;
|
use crate::core::network;
|
||||||
//TODO:: need implementation
|
use crate::core::requests::{
|
||||||
|
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||||
|
};
|
||||||
|
use crate::core::types::{Message, ReplyMarkup};
|
||||||
|
|
||||||
|
/// Use this method to send phone contacts.
|
||||||
|
/// returned.
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
struct SendContact<'a> {
|
struct SendContact<'a> {
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip_serializing)]
|
||||||
ctx: RequestContext<'a>,
|
ctx: RequestContext<'a>,
|
||||||
|
/// Unique identifier for the target chat or
|
||||||
|
/// username of the target channel (in the format @channelusername)
|
||||||
|
pub chat_id: ChatId,
|
||||||
|
/// Contact's phone number
|
||||||
|
pub phone_number: String,
|
||||||
|
/// Contact's first name
|
||||||
|
pub first_name: String,
|
||||||
|
/// Contact's last name
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub last_name: Option<String>,
|
||||||
|
/// Additional data about the contact in the form of a
|
||||||
|
/// vCard, 0-2048 bytes
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub vcard: Option<String>,
|
||||||
|
/// Sends the message silently. Users will receive a
|
||||||
|
/// notification with no sound.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub disable_notification: Option<bool>,
|
||||||
|
/// If the message is a reply, ID of the original
|
||||||
|
/// message
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub reply_to_message_id: Option<i32>,
|
||||||
|
/// InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove
|
||||||
|
/// or ForceReply Optional Additional interface options. A JSON-serialized
|
||||||
|
/// object for an inline keyboard, custom reply keyboard, instructions to
|
||||||
|
/// remove keyboard or to force a reply from the user.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub reply_markup: Option<ReplyMarkup>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Request<'a> for SendContact<'a> {
|
||||||
|
type ReturnValue = Message;
|
||||||
|
|
||||||
|
fn send(self) -> RequestFuture<'a, ResponseResult<Self::ReturnValue>> {
|
||||||
|
Box::pin(async move {
|
||||||
|
network::request_json(
|
||||||
|
&self.ctx.client,
|
||||||
|
&self.ctx.token,
|
||||||
|
"sendContact",
|
||||||
|
&self,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> SendContact<'a> {
|
||||||
|
pub(crate) fn new(
|
||||||
|
ctx: RequestContext<'a>,
|
||||||
|
chat_id: ChatId,
|
||||||
|
phone_number: String,
|
||||||
|
first_name: String,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
ctx,
|
||||||
|
chat_id,
|
||||||
|
phone_number,
|
||||||
|
first_name,
|
||||||
|
last_name: None,
|
||||||
|
vcard: None,
|
||||||
|
disable_notification: None,
|
||||||
|
reply_to_message_id: None,
|
||||||
|
reply_markup: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn chat_id<T>(mut self, chat_id: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<ChatId>,
|
||||||
|
{
|
||||||
|
self.chat_id = chat_id.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn phone_number<T>(mut self, phone_number: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<String>,
|
||||||
|
{
|
||||||
|
self.phone_number = phone_number.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn first_name<T>(mut self, first_name: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<String>,
|
||||||
|
{
|
||||||
|
self.first_name = first_name.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn last_name<T>(mut self, last_name: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<String>,
|
||||||
|
{
|
||||||
|
self.last_name = Some(last_name.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn vcard<T>(mut self, vcard: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<String>,
|
||||||
|
{
|
||||||
|
self.vcard = Some(vcard.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn disable_notification<T>(mut self, disable_notification: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<bool>,
|
||||||
|
{
|
||||||
|
self.disable_notification = Some(disable_notification.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reply_to_message_id<T>(mut self, reply_to_message_id: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<i32>,
|
||||||
|
{
|
||||||
|
self.reply_to_message_id = Some(reply_to_message_id.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reply_markup<T>(mut self, reply_markup: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<ReplyMarkup>,
|
||||||
|
{
|
||||||
|
self.reply_markup = Some(reply_markup.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,114 @@
|
||||||
use crate::core::requests::RequestContext;
|
use crate::core::network;
|
||||||
//TODO:: need implementation
|
use crate::core::requests::{
|
||||||
|
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||||
|
};
|
||||||
|
use crate::core::types::{Message, ReplyMarkup};
|
||||||
|
|
||||||
|
/// Use this method to send a native poll. A native poll can't be sent to a
|
||||||
|
/// private chat. On success, the sent Message is returned.
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
struct SendPoll<'a> {
|
struct SendPoll<'a> {
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip_serializing)]
|
||||||
ctx: RequestContext<'a>,
|
ctx: RequestContext<'a>,
|
||||||
|
/// identifier for the target chat or username of the target channel (in
|
||||||
|
/// the format @channelusername). A native poll can't be sent to a private
|
||||||
|
/// chat.
|
||||||
|
chat_id: ChatId,
|
||||||
|
/// Poll question, 1-255 characters
|
||||||
|
question: String,
|
||||||
|
/// List of answer options, 2-10 strings 1-100 characters each
|
||||||
|
options: Vec<String>,
|
||||||
|
/// Sends the message silently. Users will receive a notification with no
|
||||||
|
/// sound.
|
||||||
|
disable_notification: Option<bool>,
|
||||||
|
/// If the message is a reply, ID of the original message
|
||||||
|
reply_to_message_id: Option<i32>,
|
||||||
|
/// InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove
|
||||||
|
/// or ForceReply Optional Additional interface options. A JSON-serialized
|
||||||
|
/// object for an inline keyboard, custom reply keyboard, instructions to
|
||||||
|
/// remove reply keyboard or to force a reply from the user.
|
||||||
|
reply_markup: Option<ReplyMarkup>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Request<'a> for SendPoll<'a> {
|
||||||
|
type ReturnValue = Message;
|
||||||
|
|
||||||
|
fn send(self) -> RequestFuture<'a, ResponseResult<Self::ReturnValue>> {
|
||||||
|
Box::pin(async move {
|
||||||
|
network::request_json(
|
||||||
|
&self.ctx.client,
|
||||||
|
&self.ctx.token,
|
||||||
|
"sendPoll",
|
||||||
|
&self,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> SendPoll<'a> {
|
||||||
|
pub(crate) fn new(
|
||||||
|
ctx: RequestContext<'a>,
|
||||||
|
chat_id: ChatId,
|
||||||
|
question: String,
|
||||||
|
options: Vec<String>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
ctx,
|
||||||
|
chat_id,
|
||||||
|
question,
|
||||||
|
options,
|
||||||
|
disable_notification: None,
|
||||||
|
reply_to_message_id: None,
|
||||||
|
reply_markup: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn chat_id<T>(mut self, chat_id: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<ChatId>,
|
||||||
|
{
|
||||||
|
self.chat_id = chat_id.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn question<T>(mut self, question: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<String>,
|
||||||
|
{
|
||||||
|
self.question = question.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn options<T>(mut self, options: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<Vec<String>>,
|
||||||
|
{
|
||||||
|
self.options = options.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn disable_notification<T>(mut self, disable_notification: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<Vec<bool>>,
|
||||||
|
{
|
||||||
|
self.disable_notification = Some(disable_notification.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reply_to_message_id<T>(mut self, reply_to_message_id: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<Vec<i32>>,
|
||||||
|
{
|
||||||
|
self.reply_to_message_id = Some(reply_to_message_id.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reply_markup<T>(mut self, reply_markup: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<ReplyMarkup>,
|
||||||
|
{
|
||||||
|
self.reply_markup = Some(reply_markup.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,43 +1,158 @@
|
||||||
use crate::core::requests::{ChatId, RequestContext};
|
use crate::core::network;
|
||||||
|
use crate::core::requests::{
|
||||||
|
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||||
|
};
|
||||||
|
use crate::core::types::{Message, ReplyMarkup};
|
||||||
|
|
||||||
//TODO:: need implementation
|
/// Use this method to send information about a venue.
|
||||||
///Use this method to send information about a venue. On success, the sent
|
|
||||||
/// Message is returned.
|
/// Message is returned.
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
struct SendVenue<'a> {
|
struct SendVenue<'a> {
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip_serializing)]
|
||||||
ctx: RequestContext<'a>,
|
ctx: RequestContext<'a>,
|
||||||
/// Integer or String Yes Unique identifier for the target chat or
|
/// Unique identifier for the target chat or
|
||||||
/// username of the target channel (in the format @channelusername)
|
/// username of the target channel (in the format @channelusername)
|
||||||
chat_id: ChatId,
|
pub chat_id: ChatId,
|
||||||
/// Float number Yes Latitude of the venue
|
/// Latitude of the venue
|
||||||
latitude: f64,
|
pub latitude: f64,
|
||||||
///Float number Yes Longitude of the venue
|
/// Longitude of the venue
|
||||||
longitude: f64,
|
pub longitude: f64,
|
||||||
/// Yes Name of the venue
|
/// Name of the venue
|
||||||
title: String,
|
pub title: String,
|
||||||
///String Yes Address of the venue
|
/// Address of the venue
|
||||||
address: String,
|
pub address: String,
|
||||||
/// String Optional Foursquare identifier of the venue
|
/// Foursquare identifier of the venue
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
foursquare_id: Option<String>,
|
pub foursquare_id: Option<String>,
|
||||||
/// String Optional Foursquare type of the venue, if known. (For
|
/// Foursquare type of the venue, if known. (For
|
||||||
/// example, “arts_entertainment/default”, “arts_entertainment/aquarium” or
|
/// example, “arts_entertainment/default”, “arts_entertainment/aquarium” or
|
||||||
/// “food/icecream”.)
|
/// “food/icecream”.)
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
foursquare_type: Option<String>,
|
pub foursquare_type: Option<String>,
|
||||||
/// Boolean Optional Sends the message silently. Users will receive a
|
/// Sends the message silently. Users will receive a
|
||||||
/// notification with no sound.
|
/// notification with no sound.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
disable_notification: Option<bool>,
|
pub disable_notification: Option<bool>,
|
||||||
/// Integer Optional If the message is a reply, ID of the original
|
/// If the message is a reply, ID of the original
|
||||||
/// message
|
/// message
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
reply_to_message_id: Option<i32>,
|
pub reply_to_message_id: Option<i32>,
|
||||||
/// InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or
|
/// InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or
|
||||||
/// ForceReply Optional Additional interface options. A JSON-serialized
|
/// ForceReply Optional Additional interface options. A JSON-serialized
|
||||||
/// object for an inline keyboard, custom reply keyboard, instructions to
|
/// object for an inline keyboard, custom reply keyboard, instructions to
|
||||||
/// remove reply keyboard or to force a reply from the user.
|
/// remove reply keyboard or to force a reply from the user.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
reply_markup: Option<()>, //TODO: need concrete type
|
pub reply_markup: Option<ReplyMarkup>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Request<'a> for SendVenue<'a> {
|
||||||
|
type ReturnValue = Message;
|
||||||
|
|
||||||
|
fn send(self) -> RequestFuture<'a, ResponseResult<Self::ReturnValue>> {
|
||||||
|
Box::pin(async move {
|
||||||
|
network::request_json(
|
||||||
|
&self.ctx.client,
|
||||||
|
&self.ctx.token,
|
||||||
|
"sendVenue",
|
||||||
|
Some(&self),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> SendVenue<'a> {
|
||||||
|
pub fn new(
|
||||||
|
ctx: RequestContext<'a>,
|
||||||
|
chat_id: ChatId,
|
||||||
|
latitude: f64,
|
||||||
|
longitude: f64,
|
||||||
|
title: String,
|
||||||
|
address: String,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
ctx,
|
||||||
|
chat_id,
|
||||||
|
latitude,
|
||||||
|
longitude,
|
||||||
|
title,
|
||||||
|
address,
|
||||||
|
foursquare_id: None,
|
||||||
|
foursquare_type: None,
|
||||||
|
disable_notification: None,
|
||||||
|
reply_to_message_id: None,
|
||||||
|
reply_markup: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn chat_id<T>(mut self, chat_id: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<ChatId>,
|
||||||
|
{
|
||||||
|
self.chat_id = chat_id.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn longitude<T>(mut self, longitude: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<f64>,
|
||||||
|
{
|
||||||
|
self.longitude = longitude.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn latitude<T>(mut self, latitude: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<f64>,
|
||||||
|
{
|
||||||
|
self.latitude = latitude.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn title<T>(mut self, title: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<String>,
|
||||||
|
{
|
||||||
|
self.title = title.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn address<T>(mut self, address: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<String>,
|
||||||
|
{
|
||||||
|
self.address = address.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn foursquare_id<T>(mut self, foursquare_id: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<String>,
|
||||||
|
{
|
||||||
|
self.foursquare_id = Some(foursquare_id.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn disable_notification<T>(mut self, disable_notification: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<bool>,
|
||||||
|
{
|
||||||
|
self.disable_notification = Some(disable_notification.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn foursquare_type<T>(mut self, foursquare_type: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<bool>,
|
||||||
|
{
|
||||||
|
self.foursquare_type = Some(foursquare_type.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reply_markup<T>(mut self, reply_markup: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<ReplyMarkup>,
|
||||||
|
{
|
||||||
|
self.reply_markup = Some(ReplyMarkup.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue