/// <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); }
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§ion=messages", thread.channel_ext_id); } return(link); }
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); }
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(); } }
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)); }
public void CreateConversation() { ConversationService.AddConversation(this); }
public ApplicationController(IHostEnvironment environment, ConversationService conversationService) { _environment = environment; _conversationService = conversationService; }
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)); }
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)); }
public RaidModule(ConversationService conversationService, RaidService raidService) { _conversationService = conversationService; _raidService = raidService; }
public HttpStatusCodeResult SetRead(int id) { ConversationService.SetRead(id, DateTime.UtcNow); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public HttpStatusCodeResult Unpin(int id) { ConversationService.SetPinned(id, null); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public PartialViewResult PartialInfo(int id) { var model = ConversationService.Get(id); return(PartialView("_InfoModal", model)); }
public ActionResult InsertConversation(IEnumerable <int> users) { var conversation = ConversationService.Insert(new Conversation(), users); return(RedirectToAction <MessengerController>(c => c.Conversation(conversation.Id))); }
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; }
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())); }
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)); }
public RoboChat(SessionSettings settings) { sessionSettings = settings; this.sessionService = new SessionService(); this.conversationService = new ConversationService(sessionSettings, "RoboChat"); }
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"); }
public HttpStatusCodeResult SetUnread(int id) { ConversationService.SetRead(id, null); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public ChatController(ConversationService conversationService, IUserService userService, IMapper mapper) { _conversationService = conversationService; _userService = userService; _mapper = mapper; }
public UserModule(ConversationService conversationService, UserService userService) { _conversationService = conversationService; _userService = userService; }
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); }
public ActionResult Leave(int id) { ConversationService.RemoveMember(id); return(RedirectToAction <MessengerController>(c => c.Index(null))); }