コード例 #1
0
ファイル: Program.cs プロジェクト: Fel0ny/TeleSharp
 private static void GetLocationContactFromMessage(Message message, MessageSender sender)
 {
     if (message.Location != null)
     {
         Console.WriteLine($"Location :({message.Location.Latitude},{message.Location.Longitude})");
         Bot.SendMessage(new SendMessageParams
         {
             ChatId = sender.Id.ToString(),
             Text = $"You Send location",
             ReplyToMessage = message
         });
     }
     else if (message.Contact != null)
     {
         Console.WriteLine($"Contact :({message.Contact.FirstName},{message.Contact.LastName},{message.Contact.PhoneNumber})");
         Bot.SendMessage(new SendMessageParams
         {
             ChatId = sender.Id.ToString(),
             Text = $"You Send Contact",
             ReplyToMessage = message
         });
     }
 }
コード例 #2
0
ファイル: TeleSharp.cs プロジェクト: Fel0ny/TeleSharp
        /// <summary>
        /// Send specified location to user that requested the action
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="latitude">latitude positon of location</param>
        /// <param name="longitude">longitude position of location</param>
        /// <returns>Sent message</returns>
        public Message SendLocation(MessageSender sender, string latitude, string longitude)
        {
            if (sender == null)
                throw new ArgumentNullException(nameof(sender));

            var request = Utils.GenerateRestRequest(Resources.Method_SendLocation, Method.POST,
                new Dictionary<string, string>
                {
                    {Resources.HttpContentType, Resources.HttpMultiPartFormData}
                }
                , new Dictionary<string, object>
                {
                    {Resources.Param_ChatId, sender.Id},
                    {Resources.Param_Latitude, latitude},
                    {Resources.Param_Longitude, longitude}
                });

            return _botClient.Execute<Message>(request).Data;
        }
コード例 #3
0
ファイル: TeleSharp.cs プロジェクト: Fel0ny/TeleSharp
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="stickerBuffer"></param>
        /// <returns>Sent message</returns>
        public Message SendSticker(MessageSender sender, byte[] stickerBuffer)
        {
            if (sender == null)
                throw new ArgumentNullException(nameof(sender));

            if (stickerBuffer == null)
                throw new ArgumentNullException(nameof(stickerBuffer));

            var request = Utils.GenerateRestRequest(Resources.Method_SendSticker, Method.POST,
                new Dictionary<string, string>
                {
                    {Resources.HttpContentType, Resources.HttpMultiPartFormData}
                }
                , new Dictionary<string, object>
                {
                    {Resources.Param_ChatId, sender.Id}
                },
                new List<Tuple<string, byte[], string>>
                {
                    new Tuple<string, byte[], string>(Resources.StickerFile, stickerBuffer, Guid.NewGuid().ToString())
                });

            return _botClient.Execute<Message>(request).Data;
        }
コード例 #4
0
ファイル: TeleSharp.cs プロジェクト: Fel0ny/TeleSharp
        public Message SendDocument(MessageSender sender, byte[] fileBuffer, string filename = null)
        {
            if (sender == null)
                throw new ArgumentNullException(nameof(sender));

            if (fileBuffer == null)
                throw new ArgumentNullException(nameof(fileBuffer));

            var request = Utils.GenerateRestRequest(Resources.Method_SendDocument, Method.POST,
                new Dictionary<string, string>
                {
                    {Resources.HttpContentType, Resources.HttpMultiPartFormData}
                }
                , new Dictionary<string, object>
                {
                    {Resources.Param_ChatId, sender.Id}
                },
                new List<Tuple<string, byte[], string>>
                {
                    new Tuple<string, byte[], string>(Resources.DocumentFile, fileBuffer,
                        filename ?? Utils.ComputeFileMd5Hash(fileBuffer))
                });

            return _botClient.Execute<Message>(request).Data;
        }
コード例 #5
0
ファイル: TeleSharp.cs プロジェクト: Fel0ny/TeleSharp
        /// <summary>
        /// Forward a message from one chat to another.
        /// </summary>
        /// <param name="message">Message to forwar.</param>
        /// <param name="sender">User/group to send to</param>
        /// <returns>Message that was forwarded</returns>
        public Message ForwardMessage(Message message, MessageSender sender)
        {
            if (message == null)
                throw new ArgumentNullException(nameof(message));

            if (sender == null)
                throw new ArgumentNullException(nameof(sender));

            var request = Utils.GenerateRestRequest(Resources.Method_ForwardMessage, Method.POST,
                new Dictionary<string, string>
                {
                    {Resources.HttpContentType, Resources.HttpMultiPartFormData}
                }
                , new Dictionary<string, object>
                {
                    {Resources.Param_ChatId, sender.Id},
                    {Resources.Param_FromChatId, message.Chat?.Id ?? message.From.Id},
                    {Resources.Param_MessageId, message.MessageId}
                });

            return _botClient.Execute<Message>(request).Data;
        }
コード例 #6
0
ファイル: TeleSharp.cs プロジェクト: Fel0ny/TeleSharp
        /// <summary>
        /// Indicates that the bot is doing a specified action
        /// </summary>
        /// <param name="sender">The sender to indicate towards</param>
        /// <param name="action">The action the bot is doing (from the ChatAction class)</param>
        public void SetCurrentAction(MessageSender sender, ChatAction action)
        {
            if (sender == null)
                throw new ArgumentNullException(nameof(sender));

            string actionName = string.Empty;
            switch (action)
            {
                case ChatAction.Typing:
                    actionName = Resources.Action_typing;
                    break;
                case ChatAction.FindLocation:
                    actionName = Resources.Action_FindLocation;
                    break;
                case ChatAction.RecordVideo:
                    actionName = Resources.Action_RecordVideo;
                    break;
                case ChatAction.RecordAudio:
                    actionName = Resources.Action_RecordAudio;
                    break;
                case ChatAction.UploadPhoto:
                    actionName = Resources.Action_UploadPhoto;
                    break;
                case ChatAction.UploadVideo:
                    actionName = Resources.Action_UploadVideo;
                    break;
                case ChatAction.UploadAudio:
                    actionName = Resources.Action_UploadAudio;
                    break;
                case ChatAction.UploadDocument:
                    actionName = Resources.Action_UploadDocument;
                    break;
            }

            if (string.IsNullOrEmpty(actionName))
                return;

            var request = Utils.GenerateRestRequest(Resources.Method_SendChatAction, Method.POST, null,
                new Dictionary<string, object>
                {
                    {Resources.Param_ChatId, sender.Id},
                    {Resources.Param_Action, actionName},
                });

            _botClient.Execute(request);
        }