Ejemplo n.º 1
0
        private async void OnDirectMessageReceived(DirectMessageEvent obj)
        {
            _logger.LogInformation(
                $"Direct Message from {obj.Sender.Name} (@{obj.Sender.ScreenName}): {obj.MessageText}");

            // Important: Ignore messages originating from the bot else recursion happens
            if (obj.Sender.ScreenName == _options.BotUsername)
            {
                return;
            }

            if (_options.AllowedUsernamesConfigured() &&
                _options.AllowedUsernames.Contains(obj.Sender.ScreenName) ||
                !_options.AllowedUsernamesConfigured())
            {
                // Only respond if sender is different than the bot
                await _bot.OnTurnAsync(new TurnContext(_adapter, new Activity
                {
                    Text = obj.MessageText,
                    Type = "message",
                    From = new ChannelAccount(obj.Sender.Id, obj.Sender.ScreenName),
                    Recipient = new ChannelAccount(obj.Recipient.Id, obj.Recipient.ScreenName),
                    Conversation = new ConversationAccount {
                        Id = obj.Sender.Id
                    },
                    ChannelId = "twitter"
                }));
            }
        }
Ejemplo n.º 2
0
        private async void OnDirectMessageReceived(DirectMessageEvent obj)
        {
            _logger.LogInformation(
                $"Direct Message from {obj.Sender.Name} (@{obj.Sender.ScreenName}): {obj.MessageText}");

            // Important: Ignore messages originating from the bot else recursion happens
            if (obj.Sender.ScreenName == _options.BotUsername)
            {
                return;
            }

            if (_options.AllowedUsernamesConfigured() &&
                _options.AllowedUsernames.Contains(obj.Sender.ScreenName) ||
                !_options.AllowedUsernamesConfigured())
            {
                // Only respond if sender is different than the bot
                await _adapter.ProcessActivity(obj, _bot.OnTurnAsync);
            }
        }