diff --git a/src/core/requests/send_contact.rs b/src/core/requests/send_contact.rs index 6ffd1f2a..16cbec0e 100644 --- a/src/core/requests/send_contact.rs +++ b/src/core/requests/send_contact.rs @@ -1,7 +1,142 @@ -use crate::core::requests::RequestContext; -//TODO:: need implementation +use crate::core::network; +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)] struct SendContact<'a> { #[serde(skip_serializing)] 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, + /// Additional data about the contact in the form of a + /// vCard, 0-2048 bytes + #[serde(skip_serializing_if = "Option::is_none")] + pub vcard: Option, + /// Sends the message silently. Users will receive a + /// notification with no sound. + #[serde(skip_serializing_if = "Option::is_none")] + pub disable_notification: Option, + /// If the message is a reply, ID of the original + /// message + #[serde(skip_serializing_if = "Option::is_none")] + pub reply_to_message_id: Option, + /// 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, +} + +impl<'a> Request<'a> for SendContact<'a> { + type ReturnValue = Message; + + fn send(self) -> RequestFuture<'a, ResponseResult> { + 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(mut self, chat_id: T) -> Self + where + T: Into, + { + self.chat_id = chat_id.into(); + self + } + + pub fn phone_number(mut self, phone_number: T) -> Self + where + T: Into, + { + self.phone_number = phone_number.into(); + self + } + + pub fn first_name(mut self, first_name: T) -> Self + where + T: Into, + { + self.first_name = first_name.into(); + self + } + + pub fn last_name(mut self, last_name: T) -> Self + where + T: Into, + { + self.last_name = Some(last_name.into()); + self + } + + pub fn vcard(mut self, vcard: T) -> Self + where + T: Into, + { + self.vcard = Some(vcard.into()); + self + } + + pub fn disable_notification(mut self, disable_notification: T) -> Self + where + T: Into, + { + self.disable_notification = Some(disable_notification.into()); + self + } + + pub fn reply_to_message_id(mut self, reply_to_message_id: T) -> Self + where + T: Into, + { + self.reply_to_message_id = Some(reply_to_message_id.into()); + self + } + + pub fn reply_markup(mut self, reply_markup: T) -> Self + where + T: Into, + { + self.reply_markup = Some(reply_markup.into()); + self + } }