Beispiel #1
0
        public async Task ReceiveAsync(Message message, CancellationToken cancellationToken)
        {
            Trace.WriteLine($"From: {message.From} \tContent: {message.Content}");

            await _eventTracker.AddAsync(MessageReceived.Category, MessageReceived.Action, cancellationToken : cancellationToken);

            try
            {
                Uri feedUri;
                if (!Uri.TryCreate(message.Content.ToString(), UriKind.Absolute, out feedUri))
                {
                    await _attendance.ForwardMessageToAttendantAsync(message, _operator, cancellationToken);

                    //await SendMessageAsync("URL inválida", message.From, cancellationToken);
                    await _eventTracker.AddAsync(MessageReceivedFailed.Category, MessageReceivedFailed.Action, cancellationToken : cancellationToken);

                    return;
                }

                var user  = message.From.ToIdentity().ToString();
                var items = FeedParser.Get(feedUri);
                foreach (var item in items)
                {
                    await SendMessageAsync($"[{item.Title}]\n{item.Content}", message.From, cancellationToken);
                }
                await _eventTracker.AddAsync(MessageReceivedSuccess.Category, MessageReceivedSuccess.Action, cancellationToken : cancellationToken);
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);
                await SendMessageAsync("Houve um erro ao processar o feed.\nPor favor, tenta novamente.", message.From, cancellationToken);

                await _eventTracker.AddAsync(MessageReceivedFailed.Category, MessageReceivedFailed.Action, cancellationToken : cancellationToken);
            }
        }
        public async Task <Document> RegisterEvent(Document eventDocument, Message originatorMessage)
        {
            if (eventDocument != null)
            {
                try
                {
                    var from   = originatorMessage.From.ToIdentity();
                    var data   = (eventDocument as PlainText).Text;
                    var ev     = JsonConvert.DeserializeObject <BotEvent>(data);
                    var extras = new Dictionary <string, string>
                    {
                        { "userId", from.ToString() },
                        { "originatorMessageId", originatorMessage.Id }
                    };

                    await _eventTrack.AddAsync(ev.EventName, ev.ActionName, extras, CancellationToken.None, from);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, "Error registering event.");
                }
            }

            return(null);
        }
        public Task TrackAsync(IEventTrackExtension eventTrackExtension, SmallTalks.Core.Models.Analysis analysis, Func <string, EventTrack> eventTrackFactory, bool fireAndForget = default, CancellationToken cancellationToken = default)
        {
            var trackings = analysis.Matches.Select(m => eventTrackFactory.Invoke(m.SmallTalk));

            var trackingTasks = trackings.Select(t => eventTrackExtension.AddAsync(t.Category.Trim(), t.Action, extras: t.Extras,
                                                                                   contactIdentity: t.Contact?.Identity, fireAndForget: fireAndForget, cancellationToken: cancellationToken));

            return(Task.WhenAll(trackingTasks));
        }
 public override Task ExecuteAsync(IContext context, TrackEventSettings settings, CancellationToken cancellationToken)
 {
     return(_eventTrackExtension.AddAsync(
                settings.Category,
                settings.Action,
                settings.Label,
                value: settings.ParsedValue,
                messageId: EnvelopeReceiverContext <Message> .Envelope?.Id,
                extras: settings.Extras,
                contactIdentity: context.UserIdentity,
                fireAndForget: settings.FireAndForget ?? true,
                cancellationToken: cancellationToken
                ));
 }
Beispiel #5
0
        public async Task <Document> RegisterEvent(Document eventDocument, Message originatorMessage)
        {
            if (eventDocument != null)
            {
                var data = (eventDocument as PlainText).Text;
                var ev   = JsonConvert.DeserializeObject <BotEvent>(data);

                for (int i = 0; i < Convert.ToInt32(ev.EventQuantity); i++)
                {
                    await _eventTrack.AddAsync(ev.EventName, ev.ActionName);
                }
            }

            return(null);
        }
        public async Task ExecuteAsync(IContext context, JObject settings, CancellationToken cancellationToken)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings), $"The settings are required for '{nameof(TrackEventAction)}' action");
            }

            var category = (string)settings[CATEGORY_KEY];
            var action   = (string)settings[ACTION_KEY];

            if (string.IsNullOrEmpty(category))
            {
                throw new ArgumentException($"The '{nameof(category)}' settings value is required for '{nameof(TrackEventAction)}' action");
            }
            if (string.IsNullOrEmpty(action))
            {
                throw new ArgumentException($"The '{nameof(action)}' settings value is required for '{nameof(TrackEventAction)}' action");
            }

            var messageId = EnvelopeReceiverContext <Message> .Envelope?.Id;

            Dictionary <string, string> extras;

            if (settings.TryGetValue(nameof(extras), out var extrasToken))
            {
                extras = extrasToken.ToObject <Dictionary <string, string> >();
            }
            else
            {
                extras = new Dictionary <string, string>();
            }

            extras[MESSAGE_ID_KEY] = messageId;

            await _eventTrackExtension.AddAsync(category, action, extras, cancellationToken, context.User);
        }
 public async Task ReceiveAsync(Message message, CancellationToken cancellationToken)
 {
     await _eventTrackExtension.AddAsync("featureX", "used");
 }