public SendChatActionRequest(int chatId, ChatAction action)
 {
     _chatId = chatId;
     switch (action)
     {
         case ChatAction.FindLocation:
             _action = "find_location";
             break;
         case ChatAction.RecordAudio:
             _action = "record_audio";
             break;
         case ChatAction.RecordVideo:
             _action = "record_video";
             break;
         case ChatAction.Typing:
             _action = "typing";
             break;
         case ChatAction.UploadAudio:
             _action = "upload_audio";
             break;
         case ChatAction.UploadDocument:
             _action = "upload_document";
             break;
         case ChatAction.UploadPhoto:
             _action = "upload_photo";
             break;
         case ChatAction.UploadVideo:
             _action = "upload_video";
             break;
     }
 }
Exemple #2
0
        public void AddTypingUser(int userId, ChatAction action)
        {
            var now    = DateTime.Now;
            var max    = DateTime.MaxValue;
            var typing = new List <Tuple <int, ChatAction> >();

            lock (_typingUsersSyncRoot)
            {
                _typingUsersCache[userId] = new Tuple <DateTime, ChatAction>(TillDate(now, action), action);

                foreach (var current in _typingUsersCache)
                {
                    if (current.Value.Item1 > now)
                    {
                        if (max > current.Value.Item1)
                        {
                            max = current.Value.Item1;
                        }

                        typing.Add(new Tuple <int, ChatAction>(current.Key, current.Value.Item2));
                    }
                }
            }

            if (typing.Count > 0)
            {
                StartTypingTimer((int)(max - now).TotalMilliseconds);
                _typingCallback?.Invoke(typing);
                return;
            }

            _callback?.Invoke();
        }
Exemple #3
0
 public async Task <bool> SendChatActionAsync(
     ChatId chatId,
     ChatAction chatAction,
     Action <bool> callback = null,
     Action <string, Exception> errorCallback = null,
     CancellationToken cancellationToken      = default(CancellationToken)
     ) =>
 await SendRequestAsync <bool>(new SendChatActionRequest(chatId, chatAction), callback, errorCallback, cancellationToken);
Exemple #4
0
 public void TextWithAction(
     string text,
     ChatAction chatAction,
     CancellationToken cancellationToken = default)
 {
     this.lastText = text;
     ClientLogAll(nameof(this.TextWithAction), chatAction, text);
 }
 public async void TextWithAction(
     string text,
     ChatAction chatAction,
     CancellationToken cancellationToken = default)
 {
     this.Text(text);
     await this.botClient.SendChatActionAsync(this.message.Chat, chatAction, cancellationToken);
 }
Exemple #6
0
        /// <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);
        }
Exemple #7
0
        public bool ApplyAction(ChatAction Action)
        {
            var r = Action.Apply(this);

            if (r && OnActionApplied != null)
            {
                OnActionApplied(this, new ValuedEventArgs <ChatAction>(Action));
            }
            return(r);
        }
Exemple #8
0
        public Message CreateLeaveChatMessage(ChatRoom room)
        {
            Message    p = new Message(network, MessageType.LeaveChat);
            ChatAction c = new ChatAction();

            c.RoomId   = room.Id;
            c.RoomName = room.Name;
            p.Content  = c;
            return(p);
        }
Exemple #9
0
        /// <summary>
        /// Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient — User or GroupChat id</param>
        /// <param name="chatAction">Type of action to broadcast. Choose one, depending on what the user is about to receive.</param>
        /// <remarks>We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.</remarks>
        public async Task SendChatAction(int chatId, ChatAction chatAction)
        {
            var parameters = new Dictionary <string, object>
            {
                { "chat_id", chatId },
                { "action", chatAction.ToString() }
            };

            await SendWebRequest("sendChatAction", parameters).ConfigureAwait(false);
        }
Exemple #10
0
        public async Task <bool> SendChatAction(long chatId, ChatAction action)
        {
            var parameters = new Dictionary <string, object>
            {
                { "chat_id", chatId },
                { "action", action.ToString() }
            };

            return(await SendWebRequest <bool>("sendChatAction", parameters));
        }
Exemple #11
0
 /// <summary>
 /// Sends a notification about user activity in a chat
 /// </summary>
 public static Task <Ok> SendChatActionAsync(this Client client,
                                             long chatId       = default(long),
                                             ChatAction action = default(ChatAction))
 {
     return(client.ExecuteAsync(new SendChatAction
     {
         ChatId = chatId,
         Action = action,
     }));
 }
Exemple #12
0
        public Message CreateJoinChatMessage(ChatRoom room)
        {
            var p = new Message(network, MessageType.JoinChat);
            var c = new ChatAction();

            c.RoomId   = room.Id;
            c.RoomName = room.Name;
            p.Content  = c;
            return(p);
        }
Exemple #13
0
        /// <summary>
        /// Sends a chat action. Use this method when you need to tell the user that something is happening on
        /// the bot's side.
        /// </summary>
        /// <param name="chatId">
        /// Unique identifier for the message recipient or username of the target channel (in the format
        /// @channelusername).
        /// </param>
        /// <param name="action">Type of action to broadcast.</param>
        /// <param name="cancellationToken">
        /// A cancellation token that can be used by other objects or threads to receive notice of
        /// cancellation.
        /// </param>
        /// <returns>
        /// On success, returns the sent <see cref="Message" />.
        /// </returns>
        /// <remarks>
        /// Use this method when you need to tell the user that something is happening on the bot's side. The
        /// status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear
        /// its typing status).
        /// <example>
        /// The <c>ImageBot</c> needs some time to process a request and upload the image. Instead of sending a
        /// text message along the lines of "Retrieving image, please wait…", the bot may use
        /// <see cref="SendChatActionAsync(string,Taikandi.Telebot.Types.ChatAction,System.Threading.CancellationToken)" />
        /// with action = upload_photo. The user will see a "sending photo" status for the bot.
        /// </example>
        /// </remarks>
        public Task <bool> SendChatActionAsync([NotNull] string chatId, ChatAction action, CancellationToken cancellationToken = default(CancellationToken))
        {
            Contracts.EnsureNotNull(chatId, nameof(chatId));

            var parameters = new NameValueCollection {
                { "action", action.Value }
            };

            return(this.CallTelegramMethodAsync <bool>(cancellationToken, "sendChatAction", parameters, chatId));
        }
Exemple #14
0
        /// <summary>
        /// Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).
        /// </summary>
        /// <param name="chatId">Username of the target channel (in the format @channelusername)</param>
        /// <param name="chatAction">Type of action to broadcast. Choose one, depending on what the user is about to receive.</param>
        /// <remarks>We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.</remarks>
        public Task SendChatAction(string chatId, ChatAction chatAction)
        {
            var parameters = new Dictionary <string, object>
            {
                { "chat_id", chatId },
                { "action", chatAction.ToActionString() }
            };

            return(SendWebRequest <bool>("sendChatAction", parameters));
        }
Exemple #15
0
 public void SendChatAction(int chatID, ChatAction action)
 {
     using (WebClient webClient = new WebClient())
     {
         NameValueCollection pars = new NameValueCollection();
         pars.Add("chat_id", chatID.ToString());
         pars.Add("action", action.ToString());
         webClient.UploadValues("https://api.telegram.org/bot" + _token + "/sendChatAction", pars);
     }
 }
Exemple #16
0
        private static DateTime TillDate(DateTime now, ChatAction action)
        {
            var playGameAction = action as ChatActionStartPlayingGame;

            if (playGameAction != null)
            {
                return(now.AddSeconds(10.0));
            }

            return(now.AddSeconds(5.0));
        }
	/// <summary>
	/// Update the chat log when a player joins or leaves the server.
	/// </summary>
	/// <param name="username">Username of the player.</param>
	/// <param name="action">Action of the player.</param>
	public void UserAction(string username, ChatAction action)
	{
		string message = "";

		if (action == ChatAction.Enter)
			message = "Entered chat";
		else if (action == ChatAction.Leave)
			message = "Left chat";

		_messages.Add(new ChatData(username, message));
	}
Exemple #18
0
        public async Task <Response <bool> > SendChatActionAsync(ChatId chatId, ChatAction action)
        {
            var url = Address + Token + "/sendChatAction";

            return(await SendRequest <Response <bool> >(new Dictionary <string, object>
            {
                { "chat_id", chatId.Id },
                { "action", action.Action },
                //   {"reply_markup", replyMarkup},
            }, url));
        }
        protected void SendAction(ChatAction chatAction = ChatAction.UploadDocument)
        {
            try
            {
                TelegramClient.SendChatActionAsync(ChatId, chatAction);
            }

            catch
            {
            }
        }
Exemple #20
0
 public void SendChatAction(int _chatID, ChatAction _action)
 {
     using (WebClient webClient = new WebClient())
     {
         NameValueCollection pars = new NameValueCollection
         {
             { "chat_id", _chatID.ToString() },
             { "action", _action.ToString() }
         };
         webClient.UploadValues("https://api.telegram.org/bot" + Token + "/sendChatAction", pars);
     }
 }
Exemple #21
0
        /// <summary>
        /// Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).
        /// </summary>
        /// <param name="chatId">Unique identifier for the message recipient — User or GroupChat id</param>
        /// <param name="chatAction">Type of action to broadcast. Choose one, depending on what the user is about to receive.</param>
        /// <remarks>We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.</remarks>
        public async Task SendChatAction(int chatId, ChatAction chatAction)
        {
            const string method = "sendChatAction";

            var parameters = new Dictionary <string, object>
            {
                { "chat_id", chatId },
                { "action", chatAction.ToString() }
            };

            await SendWebRequest(method, parameters);
        }
 async void SendChatActionAsync(ChatAction chatAction)
 {
     if (!string.IsNullOrEmpty(this._chatID))
     {
         var obj = new
         {
             chat_id = this._chatID,
             action  = chatAction.GetDescription()
         };
         await RequestAsync("sendChatAction", obj);
     }
 }
        public async Task <bool> SendChatAction(string chatId, ChatAction action)
        {
            chatId.NullInspect(nameof(chatId));
            var content = new Content();

            content.Add("chat_id", chatId);
            content.Add("action", ChatActionAttribute.GetActionValue(action));

            using (var form = new FormUrlEncodedContent(content.Data))
            {
                return(await UploadFormData <bool>(form).ConfigureAwait(false));
            }
        }
Exemple #24
0
        public static string GetActionValue(ChatAction action)
        {
            var type         = typeof(ChatAction);
            var fieldInfoArr = type.GetFields();
            var fieldInfo    = fieldInfoArr.First(i => i.Name == action.ToString());

            if (fieldInfo == null)
            {
                throw new ArgumentException($"The class {type} has no field {action}.", nameof(action));
            }
            var attribute = (ChatActionAttribute)fieldInfo.GetCustomAttribute(typeof(ChatActionAttribute));

            return(attribute.Action);
        }
Exemple #25
0
    /// <summary>
    /// Update the chat log when a player joins or leaves the server.
    /// </summary>
    /// <param name="username">Username of the player.</param>
    /// <param name="action">Action of the player.</param>
    public void UserAction(string username, ChatAction action)
    {
        string message = "";

        if (action == ChatAction.Enter)
        {
            message = "Entered chat";
        }
        else if (action == ChatAction.Leave)
        {
            message = "Left chat";
        }

        _messages.Add(new ChatData(username, message));
    }
Exemple #26
0
        internal static void SeperateChatFromCurrencyActions(List <ActionBase> actions)
        {
            for (int i = 0; i < actions.Count; i++)
            {
                ActionBase action = actions[i];
                if (action is CurrencyAction)
                {
                    CurrencyAction cAction = (CurrencyAction)action;
#pragma warning disable CS0612 // Type or member is obsolete
                    ChatAction chatAction = new ChatAction(cAction.ChatText, sendAsStreamer: false, isWhisper: cAction.IsWhisper, whisperUserName: (cAction.IsWhisper) ? cAction.Username : null);
#pragma warning restore CS0612 // Type or member is obsolete
                    actions.Insert(i + 1, chatAction);
                }
            }
        }
Exemple #27
0
 private static void SetAllGameChatActionsToWhispers(CustomCommand command)
 {
     if (command != null)
     {
         foreach (ActionBase action in command.Actions)
         {
             if (action is ChatAction)
             {
                 ChatAction cAction = (ChatAction)action;
                 cAction.IsWhisper      = true;
                 cAction.SendAsStreamer = false;
             }
         }
     }
 }
Exemple #28
0
 /// <summary>
 /// Handles the Click event of the Left control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
 private void Left_Click(object sender, RoutedEventArgs e)
 {
     Application.Current.Dispatcher.Invoke((System.Action)(delegate
     {
         base.stayOpenTimer.Stop();
         base.DisplayState = Pointel.TaskbarNotifier.TaskbarNotifier.DisplayStates.Hiding;
     }));
     try
     {
         Button tempbtn = sender as Button;
         if (tempbtn.Content.ToString().Contains("Accept"))
         {
             ChatAction.Invoke("Accept", _interactionId);
         }
         else if (tempbtn.Content.ToString().Contains("Reject"))
         {
             ChatAction.Invoke("Reject", _interactionId);
         }
         else if (tempbtn.Content.ToString().Contains("Show"))
         {
             var windows = Application.Current.Windows.OfType <Window>().Where(x => x.Name == "ChatWindow");
             foreach (var win in windows)
             {
                 if (win != null && win.Tag.ToString() == _interactionId)
                 {
                     if (win.WindowState == WindowState.Minimized)
                     {
                         win.WindowState = WindowState.Normal;
                     }
                     if (!win.IsActive)
                     {
                         win.Activate();
                     }
                     win.Topmost = true;
                     win.Topmost = false;
                 }
             }
         }
     }
     catch (Exception generalException)
     {
         logger.Error("Error occurred while Left_Click() : " + generalException.ToString());
     }
 }
Exemple #29
0
        public void SetTyping(ChatAction action)
        {
            var chat = _chat;

            if (chat == null)
            {
                return;
            }

            if (chat.Type is ChatTypeSupergroup super && super.IsChannel)
            {
                return;
            }

            if (_lastTypingTime.HasValue && _lastTypingTime.Value.AddSeconds(_delay) > DateTime.Now)
            {
                return;
            }

            _lastTypingTime = DateTime.Now;
            _protoService.Send(new SendChatAction(chat.Id, action));
        }
        public void SetTyping(ChatAction action)
        {
            var chat = _chat;

            if (chat == null)
            {
                return;
            }

            if (chat.Type is ChatTypeSupergroup super && super.IsChannel || chat.Type is ChatTypePrivate privata && privata.UserId == _protoService.Options.MyId)
            {
                return;
            }

            if (_lastTypingTime.HasValue && _lastTypingTime.Value.AddSeconds(_delay) > DateTime.Now)
            {
                return;
            }

            _lastTypingTime = DateTime.Now;
            _protoService.Send(new SendChatAction(chat.Id, _threadId, action));
        }
Exemple #31
0
        internal async Task SendChatActionAsync(string chatId, ChatAction action)
        {
            string actionString = String.Empty;

            switch (action)
            {
            case ChatAction.Typing:
                actionString = "typing";
                break;

            case ChatAction.UploadPhoto:
                actionString = "upload_photo";
                break;

            case ChatAction.UploadAudio:
                actionString = "upload_audio";
                break;

            case ChatAction.UploadDocument:
                actionString = "upload_document";
                break;

            case ChatAction.UploadVideo:
                actionString = "upload_video";
                break;

            case ChatAction.FindLocation:
                actionString = "find_location";
                break;
            }

            var actionw = new ChatActionToSend
            {
                ChatId = chatId,
                Action = actionString
            };

            await api.SendRequestAsync("sendChatAction", actionw);
        }
Exemple #32
0
        public static string GetString(ChatAction ca)
        {
            switch (ca)
            {
            case ChatAction.FindLocation:
                return("find_location");

            case ChatAction.RecordAudio:
                return("record_audio");

            case ChatAction.RecordVideo:
                return("record_video");

            case ChatAction.RecordVideoNote:
                return("record_video_note");

            case ChatAction.Typing:
                return("typing");

            case ChatAction.UploadAudio:
                return("upload_audio");

            case ChatAction.UploadDocument:
                return("upload_document");

            case ChatAction.UploadPhoto:
                return("upload_photo");

            case ChatAction.UploadVideo:
                return("upload_video");

            case ChatAction.UploadVideoNote:
                return("upload_video_note");

            default:
                return(null);
            }
        }
Exemple #33
0
        /// <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);
        }
        /// <summary>
        /// Use this method when you need to tell the user that something is happening on the bot's side.
        /// The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).
        /// </summary>
        /// <remarks>
        /// We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.
        /// </remarks>
        /// <param name="chatId">Unique identifier for the message recipient — User or GroupChat id</param>
        /// <param name="action">Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location data.</param>
        /// <example>
        /// The ImageBot needs some time to process a request and upload the image.
        /// Instead of sending a text message along the lines of “Retrieving image, please wait…”, 
        /// the bot may use sendChatAction with action = upload_photo.
        /// The user will see a “sending photo” status for the bot.
        /// </example>
        public async void SendChatActionAsync(int chatId, ChatAction action)
        {
            string actionString;
            switch (action)
            {
                case ChatAction.Typing:
                    actionString = "typing";
                    break;
                case ChatAction.UploadPhoto:
                    actionString = "upload_photo";
                    break;
                case ChatAction.RecordVideo:
                    actionString = "record_video";
                    break;
                case ChatAction.UploadVideo:
                    actionString = "upload_video";
                    break;
                case ChatAction.RecordAudio:
                    actionString = "record_audio";
                    break;
                case ChatAction.UploadAudio:
                    actionString = "upload_audio";
                    break;
                case ChatAction.UploadDocument:
                    actionString = "upload_document";
                    break;
                case ChatAction.FindLocation:
                    actionString = "find_location";
                    break;
                default:
                    throw new ArgumentOutOfRangeException("action");
            }

            IRestRequest request = CreateGetRestRequest("sendChatAction");
            request.AddParameter("chat_id", chatId);
            request.AddParameter("action", actionString);

            IRestResponse response = _restClient.Execute(request);
        }
Exemple #35
0
 /// <summary>
 /// Determines whether the specified <see cref="ChatAction" /> is equal to the current
 /// <see cref="ChatAction" />.
 /// </summary>
 /// <returns>
 /// <c>true</c> if the specified <see cref="ChatAction" /> is equal to the current instance; otherwise,
 /// <c>false</c>.
 /// </returns>
 /// <param name="other">
 /// The <see cref="ChatAction" /> to compare with the current instance.
 /// </param>
 protected bool Equals(ChatAction other)
 {
     return other != null && string.Equals(this.Value, other.Value);
 }
Exemple #36
0
        public async Task<bool> SendChatActionAsync(string channelUserName, ChatAction action)
        {
            var args = new
            {
                chat_id = channelUserName,
                action = action
            };

            return await _api.CallAsync<bool>(ApiMethod.SendChatAction, args)
                .ConfigureAwait(false);
        }
 public void SendChatAction(int chatId, ChatAction action)
 {
     SendChatActionAsync(chatId, action);
 }