/// <summary>
        /// Helper method for inserting message into specified conversation.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        private Message CreateMessage(int id, MessageIn message)
        {
            Message msg = null;

            var conversation = ConversationService.Get(id);

            if (conversation == null)
            {
                ThrowResponseException(HttpStatusCode.NotFound, "Conversation with id " + id + " not found");
            }

            // create and insert new message
            try {
                msg = MessageService.Insert(new Message {
                    Text = message.Text
                }, conversation, blobs: message.Blobs, embeds: message.Embeds, meetings: message.Meetings);
            } catch (Exception ex) {
                // TODO: handle some way?
                _log.Warn(ex.Message);
            }

            return(msg);
        }
Exemple #2
0
        private string GetInboxLink(string business_id, Thread thread)
        {
            string link = "";

            try
            {
                if (!string.IsNullOrWhiteSpace(thread.ext_id))
                {
                    string conversation_id = ConversationService.FormatId(business_id, thread.ext_id);
                    var    conversation    = _conversationService.GetById(business_id, conversation_id);
                    if (conversation != null && !string.IsNullOrWhiteSpace(conversation.link))
                    {
                        link = "https://business.facebook.com" + conversation.link;
                    }
                }
            }
            catch { }
            if (string.IsNullOrWhiteSpace(link))
            {
                link = string.Format("https://business.facebook.com/{0}/messages/?folder=inbox&section=messages", thread.channel_ext_id);
            }
            return(link);
        }
Exemple #3
0
        public async void GetConversationsByUsernameWithNoConversations()
        {
            // Arrange
            var expectedConversationsCount = 0;

            _repository.GetConversationsByUserId(Arg.Any <string>()).ReturnsForAnyArgs(new List <Conversation>());
            _identityService.GetUserByUsername(Arg.Any <string>()).ReturnsForAnyArgs(new User {
                Id = "id"
            });
            ConversationService service = new ConversationService(_repository, _identityService);

            // Act
            var result = await service.GetConversationsByUsername("username");

            // Assert
            Assert.True(result.Succeeded);
            Assert.NotNull(result.Result);
            Assert.IsType <List <ConversationResponse> >(result.Result);

            var convs = result.Result as List <ConversationResponse>;

            Assert.Equal(convs.Count, expectedConversationsCount);
        }
Exemple #4
0
        public static void RegisterTestComponents <TDialog>(ContainerBuilder containerBuilder, ChannelAccount from, Func <IComponentContext, TDialog> registerDialogFunc = null)
            where TDialog : IDialog <object>
        {
            var conversationService = new ConversationService(from);

            containerBuilder
            .Register(c => conversationService)
            .As <IConversationService <IMessageActivity> >()
            .SingleInstance();

            if (registerDialogFunc == null)
            {
                containerBuilder
                .RegisterType <TDialog>()
                .Keyed <IDialog <object> >(Constants.TargetDialogKey)
                .InstancePerDependency();
            }
            else
            {
                containerBuilder.Register(registerDialogFunc)
                .Keyed <IDialog <object> >(Constants.TargetDialogKey)
                .InstancePerDependency();
            }
        }
Exemple #5
0
        public ActionResult Conversations(Query query)
        {
            // limit page size to 25
            query.Top = Math.Min(query.Top ?? MAX_PAGE_SIZE, MAX_PAGE_SIZE);

            var cq = new ConversationQuery(query);

            cq.UserId  = User.Id;
            cq.OrderBy = "PinnedAt DESC, LastMessageAt DESC";

            var model = new Messenger();

            model.IsMessenger   = false;
            model.Conversations = ConversationService.Search(cq);

            // search or infinite scroll, return partial view
            if (Request.IsAjaxRequest())
            {
                model.IsMessenger = IsMessenger(Request.Headers["Referer"]);
                return(PartialView("_Conversations", model));
            }

            return(View(model));
        }
 public Conversation Read(int id)
 {
     ConversationService.SetRead(id, readAt: DateTime.UtcNow);
     return(ConversationService.Get(id));
 }
Exemple #7
0
 public void CreateConversation()
 {
     ConversationService.AddConversation(this);
 }
Exemple #8
0
 public ApplicationController(IHostEnvironment environment,
                              ConversationService conversationService)
 {
     _environment         = environment;
     _conversationService = conversationService;
 }
Exemple #9
0
        public ActionResult Messenger(int?id, QueryOptions opts)
        {
            // limit page size to 25
            opts.Top = Math.Min(opts.Top ?? MAX_PAGE_SIZE, MAX_PAGE_SIZE);

            var model = new Messenger {
                ConversationId = id
            };

            if (model.ConversationId != null)
            {
                // get selected conversation
                model.Conversation = ConversationService.Get(model.ConversationId.Value);
                if (model.Conversation == null)
                {
                    ThrowResponseException(HttpStatusCode.NotFound, $"Conversation with id {model.ConversationId.Value} not found");
                }
            }
            else
            {
                // get most recent conversation
                model.Conversation = ConversationService.Search(new ConversationQuery {
                    OrderBy = "PinnedAt DESC, LastMessageAt DESC", Top = 1
                }).FirstOrDefault();
            }

            if (model.Conversation != null)
            {
                if (model.ConversationId != null)
                {
                    // mark conversation as read (if needed)
                    if (model.Conversation.ReadAt == null)
                    {
                        model.Conversation = ConversationService.SetRead(model.Conversation.Id, DateTime.UtcNow);
                    }
                    else if (model.Conversation.ReadAt < model.Conversation.LastMessage?.CreatedAt)
                    {
                        // NOTE: do not assign the read conversation to model.Conversation since that will prevent rendering of the "New messages" separator
                        ConversationService.SetRead(model.Conversation.Id, DateTime.UtcNow);
                    }
                }

                // get first page of messages (and reverse them for easier rendering in correct order)
                model.Messages = ConversationService.GetMessages(model.Conversation.Id, new QueryOptions {
                    Top = MAX_PAGE_SIZE
                });
                model.Messages.Reverse();
            }

            // Meetings
            model.ZoomEnabled  = ConfigurationService.ZoomMeetings;
            model.TeamsEnabled = ConfigurationService.TeamsMeetings;

            // NOTE: we load conversations last so that selected conversation does not appear unread in the list
            var query = new ConversationQuery(opts);

            query.UserId        = User.Id;
            query.OrderBy       = "PinnedAt DESC, LastMessageAt DESC";
            model.Conversations = ConversationService.Search(query);

            // make sure selected conversation is visible in conversations list
            while (model.Conversation != null && !model.Conversations.Any(x => x.Id == model.Conversation.Id))
            {
                query.Top          += PageSizes.First();
                model.Conversations = ConversationService.Search(query);
            }

            return(View(nameof(Messenger), model));
        }
Exemple #10
0
 public BroadcastMessageCommand(TelegramChatService chatService, ConversationService conversationService)
 {
     this.chatService         = chatService;
     this.conversationService = conversationService;
 }
        public ChatParameters Post([FromBody] ChatParameters chatParameters)
        {
            ConversationService conversation = new ConversationService();

            return(conversation.StartConversation(chatParameters.Text, chatParameters.Context));
        }
Exemple #12
0
 public RaidModule(ConversationService conversationService, RaidService raidService)
 {
     _conversationService = conversationService;
     _raidService         = raidService;
 }
Exemple #13
0
 public HttpStatusCodeResult SetRead(int id)
 {
     ConversationService.SetRead(id, DateTime.UtcNow);
     return(new HttpStatusCodeResult(HttpStatusCode.OK));
 }
Exemple #14
0
 public HttpStatusCodeResult Unpin(int id)
 {
     ConversationService.SetPinned(id, null);
     return(new HttpStatusCodeResult(HttpStatusCode.OK));
 }
Exemple #15
0
        public PartialViewResult PartialInfo(int id)
        {
            var model = ConversationService.Get(id);

            return(PartialView("_InfoModal", model));
        }
Exemple #16
0
        public ActionResult InsertConversation(IEnumerable <int> users)
        {
            var conversation = ConversationService.Insert(new Conversation(), users);

            return(RedirectToAction <MessengerController>(c => c.Conversation(conversation.Id)));
        }
Exemple #17
0
 public StudentAssignmentsController(AppDbContext db, IMapper mapper, IUserService userService,
                                     AssignmentService assignmentService, AttachmentService attachmentService, GroupService groupService,
                                     StudentAssignmentService studentAssignmentService, ConversationService conversationService)
 {
     _db                       = db;
     _mapper                   = mapper;
     _userService              = userService;
     _assignmentService        = assignmentService;
     _attachmentService        = attachmentService;
     _groupService             = groupService;
     _studentAssignmentService = studentAssignmentService;
     _conversationService      = conversationService;
 }
Exemple #18
0
 private void ConnectToWatson()
 {
     _conversation = new ConversationService("apikey", "H4xzsMTLgmvfSF9Br2Qb0avcVAGLkLTluWBfEz7dOGHt", "2019-02-28");
     _conversation.SetEndpoint("https://gateway.watsonplatform.net/assistant/api");
 }
 public IHttpActionResult GetUnread()
 {
     return(Ok(ConversationService.GetUnread().Count()));
 }
Exemple #20
0
 public ClientWatsonAssistant()
 {
     _conversation = new ConversationService("afcea3f6-1a23-4f95-aa62-51304447f1a2", "p0nzObAmUj42", "2018-02-16");
     _conversation.SetEndpoint("https://gateway.watsonplatform.net/assistant/api");
     _workspaceID = "56e7c413-006c-42b5-b618-c87f1c549966";
 }
        public IHttpActionResult List()
        {
            var conversations = ConversationService.Search(new ConversationQuery());

            return(Ok(conversations));
        }
Exemple #22
0
 public RoboChat(SessionSettings settings)
 {
     sessionSettings          = settings;
     this.sessionService      = new SessionService();
     this.conversationService = new ConversationService(sessionSettings, "RoboChat");
 }
Exemple #23
0
 public RaidEdit(ConversationService conversationService, RaidService raidService)
 {
     _conversationService = conversationService;
     _raidService         = raidService;
 }
 private void ConnectToWatson()
 {
     _conversation = new ConversationService("apikey", "ZEHSwO82bnTm820bz4tqTQvZvKIvItzH3lzABwuUver8", "2019-02-28");
     _conversation.SetEndpoint("https://gateway.watsonplatform.net/assistant/api");
 }
Exemple #25
0
 public HttpStatusCodeResult SetUnread(int id)
 {
     ConversationService.SetRead(id, null);
     return(new HttpStatusCodeResult(HttpStatusCode.OK));
 }
Exemple #26
0
 public ChatController(ConversationService conversationService, IUserService userService, IMapper mapper)
 {
     _conversationService = conversationService;
     _userService         = userService;
     _mapper = mapper;
 }
Exemple #27
0
 public UserModule(ConversationService conversationService, UserService userService)
 {
     _conversationService = conversationService;
     _userService         = userService;
 }
Exemple #28
0
 public HttpStatusCodeResult RemoveMember(int id, int user)
 {
     ConversationService.RemoveMember(id, user);
     return(new HttpStatusCodeResult(HttpStatusCode.OK));
 }
        public async Task ShouldDeleteConversationCorrectly()
        {
            const long conversationId = 1;
            const long messageId      = 1;

            var firedEventsCount = 0;

            var initiator = new User {
                Id = 1
            };
            var invited = new List <User>
            {
                new User
                {
                    Id = 2
                },
                new User
                {
                    Id = 3
                }
            };

            var conversationUsers = invited.Union(new List <User> {
                initiator
            }).Select(u => new ConversationUser()
            {
                ConversationId = conversationId, UserId = u.Id
            }).ToList();

            var conversationUserRepository = new TestRepository <ConversationUser>(conversationUsers);
            var blackListRepository        = new TestRepository <BlackList>();
            var chatActionRepository       = new TestRepository <ChatAction>(new List <ChatAction>()
            {
                new ChatAction()
                {
                    ConversationId = conversationId
                }
            });
            var messageRepository = new TestRepository <Message>(new List <Message>()
            {
                new Message()
                {
                    Id             = messageId,
                    ConversationId = conversationId,
                    SenderId       = initiator.Id,
                    Text           = "test"
                }
            });;
            var attachmentRepository = new TestRepository <Attachment>(new List <Attachment>()
            {
                new Attachment
                {
                    Id        = 1,
                    MessageId = messageId
                }
            });

            var blackListService        = new BlackListService(blackListRepository, _mapper);
            var conversationUserService = new ConversationUserService(conversationUserRepository, _mapper);


            var messageService = new MessageService(messageRepository, attachmentRepository, _timeProvider, _attachmentContentProvider, blackListService, conversationUserService, _mapper);

            var conversation = new Conversation
            {
                Id      = conversationId,
                OwnerId = initiator.Id,
                Users   = conversationUsers
            };
            var conversationRepository = new TestRepository <Conversation>(new List <Conversation>()
            {
                conversation
            });
            var conversationService = new ConversationService(conversationRepository, conversationUserRepository, chatActionRepository, blackListService, messageService, _timeProvider, _mapper);

            conversationService.OnConversationDeleted += (c) => firedEventsCount++;

            await conversationService.DeleteConversationAsync(initiator.Id, conversation.Id);

            Assert.Empty(conversationRepository.All());
            Assert.Empty(messageRepository.All());
            Assert.Empty(attachmentRepository.All());
            Assert.Empty(conversationUserRepository.All());
            Assert.Equal(1, firedEventsCount);
        }
Exemple #30
0
 public ActionResult Leave(int id)
 {
     ConversationService.RemoveMember(id);
     return(RedirectToAction <MessengerController>(c => c.Index(null)));
 }