Search in sources :

Example 6 with User

use of org.finos.symphony.toolkit.workflow.content.User in project spring-bot by finos.

the class TimeFinder method accept.

@Override
public void accept(Action t) {
    try {
        if (t instanceof SimpleMessageAction) {
            Message m = ((SimpleMessageAction) t).getMessage();
            User currentUser = t.getUser();
            Addressable a = t.getAddressable();
            String messageInString = m.getText();
            CoreDocument document = new CoreDocument(messageInString);
            stanfordCoreNLP.annotate(document);
            for (CoreEntityMention cem : document.entityMentions()) {
                System.out.println("temporal expression: " + cem.text());
                System.out.println("temporal value: " + cem.coreMap().get(TimeAnnotations.TimexAnnotation.class));
                Timex timex = cem.coreMap().get(TimeAnnotations.TimexAnnotation.class);
                LocalDateTime ldt = toLocalTime(timex);
                if (ldt != null) {
                    Optional<ReminderList> rl = h.getLastFromHistory(ReminderList.class, a);
                    int remindBefore;
                    if (rl.isPresent()) {
                        remindBefore = rl.get().getRemindBefore();
                    } else {
                        remindBefore = reminderProperties.getDefaultRemindBefore();
                    }
                    ldt = ldt.minus(remindBefore, ChronoUnit.MINUTES);
                    Reminder reminder = new Reminder();
                    reminder.setDescription(messageInString);
                    reminder.setLocalTime(ldt);
                    reminder.setAuthor(currentUser);
                    WorkResponse wr = new WorkResponse(a, reminder, WorkMode.EDIT);
                    rh.accept(wr);
                }
            }
        }
    } catch (Exception e) {
        errorHandler.handleError(e);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) User(org.finos.symphony.toolkit.workflow.content.User) Message(org.finos.symphony.toolkit.workflow.content.Message) CoreDocument(edu.stanford.nlp.pipeline.CoreDocument) ParseException(java.text.ParseException) CoreEntityMention(edu.stanford.nlp.pipeline.CoreEntityMention) SimpleMessageAction(org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction) Addressable(org.finos.symphony.toolkit.workflow.content.Addressable) TimeAnnotations(edu.stanford.nlp.time.TimeAnnotations) Timex(edu.stanford.nlp.time.Timex) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse)

Example 7 with User

use of org.finos.symphony.toolkit.workflow.content.User in project spring-bot by finos.

the class TestHandlerMapping method pressButton.

private void pressButton(String s) throws Exception {
    EntityJson jsonObjects = new EntityJson();
    jsonObjects.put("1", new SymphonyUser(123l, "gaurav", "gaurav@example.com"));
    jsonObjects.put("2", new HashTag("SomeTopic"));
    Chat r = new SymphonyRoom("The Room Where It Happened", "abc123");
    User author = new SymphonyUser(ROB_EXAMPLE_ID, ROB_NAME, ROB_EXAMPLE_EMAIL);
    Object fd = new StartClaim();
    Action a = new FormAction(r, author, fd, s, jsonObjects);
    Action.CURRENT_ACTION.set(a);
    mc.accept(a);
}
Also used : Action(org.finos.symphony.toolkit.workflow.actions.Action) SimpleMessageAction(org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction) FormAction(org.finos.symphony.toolkit.workflow.actions.FormAction) EntityJson(org.finos.symphony.toolkit.json.EntityJson) User(org.finos.symphony.toolkit.workflow.content.User) SymphonyUser(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser) StartClaim(org.finos.symphony.toolkit.workflow.fixture.StartClaim) HashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag) Chat(org.finos.symphony.toolkit.workflow.content.Chat) FormAction(org.finos.symphony.toolkit.workflow.actions.FormAction) SymphonyUser(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser) SymphonyRoom(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom)

Example 8 with User

use of org.finos.symphony.toolkit.workflow.content.User in project spring-bot by finos.

the class TestHandlerMapping method execute.

private void execute(String s) throws Exception {
    EntityJson jsonObjects = new EntityJson();
    jsonObjects.put("1", new SymphonyUser(123l, "gaurav", "gaurav@example.com"));
    jsonObjects.put("2", new Taxonomy(Arrays.asList(new HashTag("SomeTopic"))));
    Message m = smp.parse("<messageML>/" + s + "</messageML>", jsonObjects);
    Chat r = new SymphonyRoom("The Room Where It Happened", "abc123");
    User author = new SymphonyUser(ROB_EXAMPLE_ID, ROB_NAME, ROB_EXAMPLE_EMAIL);
    Action a = new SimpleMessageAction(r, author, m, jsonObjects);
    Action.CURRENT_ACTION.set(a);
    mc.accept(a);
}
Also used : Action(org.finos.symphony.toolkit.workflow.actions.Action) SimpleMessageAction(org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction) FormAction(org.finos.symphony.toolkit.workflow.actions.FormAction) EntityJson(org.finos.symphony.toolkit.json.EntityJson) User(org.finos.symphony.toolkit.workflow.content.User) SymphonyUser(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser) Message(org.finos.symphony.toolkit.workflow.content.Message) Taxonomy(org.symphonyoss.Taxonomy) HashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag) Chat(org.finos.symphony.toolkit.workflow.content.Chat) SimpleMessageAction(org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction) SymphonyUser(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser) SymphonyRoom(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom)

Example 9 with User

use of org.finos.symphony.toolkit.workflow.content.User in project spring-bot by finos.

the class TestRoomAndUsersBuilder method testEnsureRoom.

@Test
public void testEnsureRoom() {
    ruBuilder.setDefaultAdministrators(Collections.singletonList(new SymphonyUser(1111l)));
    // create room
    when(streamsApi.v1StreamsListPost(Mockito.isNull(), Mockito.any(), Mockito.eq(0), Mockito.eq(50))).thenAnswer(c -> {
        StreamList out = new StreamList();
        out.add(new StreamAttributes().roomAttributes(new RoomSpecificStreamAttributes().name("Some Test Room")).id("abc123").streamType(new StreamType().type(TypeEnum.ROOM)));
        UserIdList l = new UserIdList();
        // robski
        l.add(765l);
        // the bot
        l.add(654321l);
        out.add(new StreamAttributes().streamAttributes(new ConversationSpecificStreamAttributes().members(l)).id("283746").streamType(new StreamType().type(TypeEnum.IM)));
        return out;
    });
    when(streamsApi.v3RoomCreatePost(any(), isNull())).then(a -> new V3RoomDetail().roomSystemInfo(new RoomSystemInfo().id("456")).roomAttributes(new V3RoomAttributes()._public(false).name("Some Test Room").description("Still Bogus")));
    when(streamsApi.v3RoomSearchPost(Mockito.any(), Mockito.isNull(), Mockito.isNull(), Mockito.isNull())).then(a -> new V3RoomSearchResults().rooms(Collections.emptyList()));
    SymphonyRoom rd = new SymphonyRoom("Some Test Room", null);
    SymphonyUser su = new SymphonyUser(2342l);
    SymphonyRoom out = ruBuilder.ensureChat(rd, Collections.singletonList(su), SymphonyConversations.simpleMeta("Automated Test Room Created", true));
    assertEquals("Some Test Room", out.getName());
    assertEquals(2, ruBuilder.getAllConversations().size());
    assertEquals("456", out.getStreamId());
    // return members
    MembershipList ml = new MembershipList();
    ml.add(new MemberInfo().id(123l).owner(true));
    when(rmApi.v2RoomIdMembershipListGet(Mockito.anyString(), Mockito.isNull())).thenReturn(ml);
    List<User> chatMembers = ruBuilder.getChatMembers(out);
    Assertions.assertEquals(Collections.singletonList(new SymphonyUser(123l, ROB_NAME, ROB_EXAMPLE_EMAIL)), chatMembers);
}
Also used : MembershipList(com.symphony.api.model.MembershipList) StreamType(com.symphony.api.model.StreamType) V3RoomDetail(com.symphony.api.model.V3RoomDetail) User(org.finos.symphony.toolkit.workflow.content.User) SymphonyUser(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser) RoomSystemInfo(com.symphony.api.model.RoomSystemInfo) StreamList(com.symphony.api.model.StreamList) ConversationSpecificStreamAttributes(com.symphony.api.model.ConversationSpecificStreamAttributes) RoomSpecificStreamAttributes(com.symphony.api.model.RoomSpecificStreamAttributes) StreamAttributes(com.symphony.api.model.StreamAttributes) RoomSpecificStreamAttributes(com.symphony.api.model.RoomSpecificStreamAttributes) SymphonyRoom(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom) UserIdList(com.symphony.api.model.UserIdList) ConversationSpecificStreamAttributes(com.symphony.api.model.ConversationSpecificStreamAttributes) MemberInfo(com.symphony.api.model.MemberInfo) V3RoomAttributes(com.symphony.api.model.V3RoomAttributes) SymphonyUser(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser) V3RoomSearchResults(com.symphony.api.model.V3RoomSearchResults) Test(org.junit.jupiter.api.Test)

Example 10 with User

use of org.finos.symphony.toolkit.workflow.content.User in project spring-bot by finos.

the class PresentationMLHandler method accept.

@Override
public void accept(V4Event t) {
    try {
        V4MessageSent ms = t.getPayload().getMessageSent();
        if ((ms != null) && (!ms.getMessage().getUser().getEmail().equals(botIdentity.getEmail()))) {
            // ok, this is a message, and it's from a third party.  Parse it.
            EntityJson ej = jsonConverter.readValue(ms.getMessage().getData());
            Message words = messageParser.parse(ms.getMessage().getMessage(), ej);
            Addressable rr = ruBuilder.loadRoomById(ms.getMessage().getStream().getStreamId());
            User u = ruBuilder.loadUserById(ms.getMessage().getUser().getUserId());
            // TODO: multi-user chat (not room)
            rr = rr == null ? u : rr;
            SimpleMessageAction sma = new SimpleMessageAction(rr, u, words, ej);
            try {
                Action.CURRENT_ACTION.set(sma);
                for (ActionConsumer c : messageConsumers) {
                    c.accept(sma);
                }
            } finally {
                Action.CURRENT_ACTION.set(Action.NULL_ACTION);
            }
        }
    } catch (Exception e) {
        LOG.error("Couldn't handle event " + t, e);
    }
}
Also used : EntityJson(org.finos.symphony.toolkit.json.EntityJson) User(org.finos.symphony.toolkit.workflow.content.User) Message(org.finos.symphony.toolkit.workflow.content.Message) ActionConsumer(org.finos.symphony.toolkit.workflow.actions.consumers.ActionConsumer) SimpleMessageAction(org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction) V4MessageSent(com.symphony.api.model.V4MessageSent) Addressable(org.finos.symphony.toolkit.workflow.content.Addressable)

Aggregations

User (org.finos.symphony.toolkit.workflow.content.User)11 SimpleMessageAction (org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction)5 EntityJson (org.finos.symphony.toolkit.json.EntityJson)4 Addressable (org.finos.symphony.toolkit.workflow.content.Addressable)4 Chat (org.finos.symphony.toolkit.workflow.content.Chat)4 Message (org.finos.symphony.toolkit.workflow.content.Message)4 SymphonyRoom (org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom)4 SymphonyUser (org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser)4 FormAction (org.finos.symphony.toolkit.workflow.actions.FormAction)3 WorkResponse (org.finos.symphony.toolkit.workflow.response.WorkResponse)3 HashTag (org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag)3 SymphonyIdentity (com.symphony.api.id.SymphonyIdentity)2 MembershipList (com.symphony.api.model.MembershipList)2 StreamAttributes (com.symphony.api.model.StreamAttributes)2 StreamList (com.symphony.api.model.StreamList)2 StreamType (com.symphony.api.model.StreamType)2 V3RoomAttributes (com.symphony.api.model.V3RoomAttributes)2 V3RoomDetail (com.symphony.api.model.V3RoomDetail)2 V3RoomSearchResults (com.symphony.api.model.V3RoomSearchResults)2 ArrayList (java.util.ArrayList)2