コード例 #1
0
 public WatsonChatConversation(
     IMessageHubManager messageHubManager,
     IHubCallerClients clientsManager,
     IUserTracker <HubWithPresence> userTracker,
     UOW uow)
     : base(messageHubManager, clientsManager, userTracker, uow)
 {
 }
コード例 #2
0
 public DefaultConversationHandler(
     IMessageHubManager messageHubManager,
     IHubCallerClients clientsManager,
     IUserTracker <HubWithPresence> userTracker,
     UOW uow
     )
 {
     this.messageHubManager = messageHubManager ?? throw new System.ArgumentNullException(nameof(messageHubManager));
     this.clientsManager    = clientsManager ?? throw new System.ArgumentNullException(nameof(clientsManager));
     this.userTracker       = userTracker ?? throw new System.ArgumentNullException(nameof(userTracker));
     this.uow = uow ?? throw new System.ArgumentNullException(nameof(uow));
 }
コード例 #3
0
 public HumanAgentConversation(
     IMessageHubManager messageHubManager,
     IHubCallerClients clientsManager,
     IUserTracker<HubWithPresence> userTracker,
     UOW uow,
     PushNotificationService pushNotificationService
 ) : base(
         messageHubManager, 
         clientsManager, 
         userTracker, 
         uow
     )
 {
     this.pushNotificationService = pushNotificationService ?? throw new System.ArgumentNullException(nameof(pushNotificationService));
 }
コード例 #4
0
        public async Task SendPushMessages(
            IEnumerable <TokenDetail> agent,
            string channelId,
            LivechatUserTokenRepository livechatTokenRep,
            IMessageHubManager messageHubManager = null,
            LogRepository logMessageRepository   = null,
            string defaultDataAction             = "JoinNewChannel",
            string defaultNotificationTitle      = "Novo cliente!",
            string defaultNotificationBody       = "Um cliente quer falar com você, rápido!")
        {
            foreach (var token in agent)
            {
                // For new desktop version, it doesn't include firebase token
                if (token.Device.ToLower() == "desktop" && !string.IsNullOrEmpty(token.Version))
                {
                    if (string.IsNullOrEmpty(token.Token))
                    {
                        continue;
                    }

                    var package = new Dictionary <string, string>
                    {
                        { "body", "Um cliente quer falar com você, Rápido!" },
                        { "title", "Novo cliente!" },
                        { "icon", "/static/img/launcher-icon-4x.png" },
                        { "priority", "high" },
                        { "channelId", channelId },
                        { "sound", "default" }
                    };

                    await messageHubManager.SendClientMessage(
                        token.Token,
                        HubMessages.NEW_CUSTOMER_ALERT,
                        package);

                    continue;
                }

                using (var client = new WebClient())
                {
                    client.Headers["Authorization"] = "key=AAAAJu4yfbc:APA91bHpQ4yVwm4zJ6Tvv73fdutEM17oJE8WzwRTWTgG9KMRfhEwD1Rd04YVB78pvEbwxC5HYWDh8evTJ1GLBRWtTWRT0S3fdSmljNlPSwprBkbZsx2pdlKFfIRSGf9fPy1CCfIu7nxI";
                    client.Headers["Content-Type"]  = "application/json";

                    var clientMobileMessage = $"{{\"title\":\"{defaultNotificationTitle}\",\"text\":\"{defaultNotificationBody}\"," +
                                              $"\"attachments\":[],\"data\":{{\"action\": \"{defaultDataAction}\",\"p1\":\"{channelId}\"}}," +
                                              $"\"trigger\":{{\"in\":1,\"unit\":\"second\"}},\"foreground\":true,\"autoClear\":true," +
                                              $"\"defaults\":0,\"groupSummary\":false,\"id\":0,\"launch\":true,\"led\":true," +
                                              $"\"lockscreen\":true,\"number\":0,\"priority\":1,\"showWhen\":true,\"silent\":false," +
                                              $"\"smallIcon\":\"res://icon\",\"sound\":true,\"vibrate\":true,\"wakeup\":true}}";


                    var package = new Dictionary <string, object>
                    {
                        { "to", token.Token },
                        { "notification", new Dictionary <string, string>
                          {
                              { "body", "Um cliente quer falar com você, Rápido!" },
                              { "title", "Novo cliente!" },
                              { "icon", "/static/img/launcher-icon-4x.png" },
                              { "priority", "high" },
                              { "click_action", $"FCM_PLUGIN_ACTIVITY" },
                              { "sound", "default" }
                          } },
                        { "data", new Dictionary <string, string>()
                          {
                              { "body", "Um cliente quer falar com você, rápido!" },
                              { "title", "Novo cliente!" },
                              { "click_action", $"{BASE_URL}/newchat?channelId={channelId}" },
                              { "chat_mobile", clientMobileMessage }
                          } }
                    };

                    if (token.Device.ToLower() == "desktop")
                    {
                        (package["notification"] as Dictionary <string, string>)["click_action"] = $"{BASE_URL}/newchat?channelId={channelId}";
                    }
                    else
                    {
                        package.Remove("notification");
                    }

                    var jsonPackage = JsonConvert.SerializeObject(package);
                    var response    = client.UploadStringTaskAsync("https://fcm.googleapis.com/fcm/send", jsonPackage);

                    /*if (response.Contains("NotRegistered"))
                     *  await livechatTokenRep.RemoveInvalidToken(token.Token); */

                    if (logMessageRepository != null)
                    {
                        await logMessageRepository.RecLog(
                            NopLogLevel.Info,
                            $"Token sent to {token.Token}",
                            $"Message response: {response} \n\n LivechatUserId: {token.LivechatUserId}"
                            );
                    }
                }
            }
        }