Search in sources :

Example 6 with V4Stream

use of com.symphony.api.model.V4Stream in project spring-bot by finos.

the class RoomWelcomeEventConsumerIT method testRoomCreated.

@Test
public void testRoomCreated() {
    RoomWelcomeEventConsumer rwec = new RoomWelcomeEventConsumer(messages, users, bot);
    V4Event event = new V4Event().payload(new V4Payload().roomCreated(new V4RoomCreated().roomProperties(new V4RoomProperties().name("Big Room")).stream(new V4Stream().streamId(NEW_ROOM_STREAM_ID))));
    rwec.accept(event);
    Mockito.verify(messages, Mockito.times(1)).v4StreamSidMessageCreatePost(Mockito.isNull(), Mockito.matches(Pattern.quote(NEW_ROOM_STREAM_ID)), Mockito.isNotNull(), Mockito.isNotNull(), Mockito.isNull(), Mockito.isNull(), Mockito.isNull(), Mockito.isNull());
    Mockito.clearInvocations(messages);
}
Also used : V4RoomCreated(com.symphony.api.model.V4RoomCreated) V4Event(com.symphony.api.model.V4Event) V4Stream(com.symphony.api.model.V4Stream) V4Payload(com.symphony.api.model.V4Payload) V4RoomProperties(com.symphony.api.model.V4RoomProperties) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with V4Stream

use of com.symphony.api.model.V4Stream in project spring-bot by finos.

the class KoreAIEventHandler method accept.

@Override
public void accept(V4Event t) {
    try {
        V4MessageSent ms = t.getPayload().getMessageSent();
        V4User u = t.getInitiator().getUser();
        if (ms != null) {
            V4Stream stream = ms.getMessage().getStream();
            String text = extractText(ms);
            EntityJson ej = parseEntityJson(ms.getMessage().getData());
            if (!u.getEmail().equals(botIdentity.getEmail()) && (isAddressed(stream, ej, text))) {
                try {
                    Address a = buildAddress(u, stream);
                    text = normalizeText(text);
                    requester.send(a, text);
                } catch (Exception e) {
                    LOG.error("Couldn't handle message {}", ms);
                }
            }
        }
        // handle form submits
        V4SymphonyElementsAction elements = t.getPayload().getSymphonyElementsAction();
        if (elements != null) {
            String formId = elements.getFormId();
            if (formId.equals("koreai-choice")) {
                @SuppressWarnings("unchecked") String button = ((Map<String, String>) elements.getFormValues()).get("action");
                try {
                    Address a = buildAddress(u, elements.getStream());
                    requester.send(a, button);
                } catch (Exception e) {
                    LOG.error("Couldn't handle form submission {}", ms);
                }
            }
        }
    } catch (Exception e) {
        LOG.error("Couldn't handle stream event " + t, e);
    }
}
Also used : EntityJson(org.finos.symphony.toolkit.json.EntityJson) Address(org.finos.symphony.toolkit.koreai.Address) V4SymphonyElementsAction(com.symphony.api.model.V4SymphonyElementsAction) V4MessageSent(com.symphony.api.model.V4MessageSent) V4User(com.symphony.api.model.V4User) V4Stream(com.symphony.api.model.V4Stream) Map(java.util.Map) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 8 with V4Stream

use of com.symphony.api.model.V4Stream in project spring-bot by finos.

the class BotIT method testSendMessageRoomWithSlashPrivateBot.

@Test
public void testSendMessageRoomWithSlashPrivateBot() {
    // the direct bot won't talk in rooms
    V4Event in = new V4Event().initiator(new V4Initiator().user(new V4User().email("rob@example.com").displayName("Rob Example").userId(2438923l))).payload(new V4Payload().messageSent(new V4MessageSent().message(new V4Message().message("<div>/hello</div>").data("{}").stream(new V4Stream().streamId("ABC123").streamType("ROOM")))));
    getPrivateBot().sendToConsumer(in);
    littleSleep();
    wireMockRule.verify(0, WireMock.postRequestedFor(urlPathMatching("/kore2")));
}
Also used : V4Message(com.symphony.api.model.V4Message) V4Initiator(com.symphony.api.model.V4Initiator) V4MessageSent(com.symphony.api.model.V4MessageSent) V4Event(com.symphony.api.model.V4Event) V4User(com.symphony.api.model.V4User) V4Stream(com.symphony.api.model.V4Stream) V4Payload(com.symphony.api.model.V4Payload) Test(org.junit.jupiter.api.Test)

Example 9 with V4Stream

use of com.symphony.api.model.V4Stream in project spring-bot by finos.

the class BotIT method testSendMessageIMPrivateBot.

@Test
public void testSendMessageIMPrivateBot() {
    V4Event in = new V4Event().initiator(new V4Initiator().user(new V4User().email("rob@example.com").displayName("Rob Example").userId(2438923l))).payload(new V4Payload().messageSent(new V4MessageSent().message(new V4Message().message("<div>hello</div>").data("{}").stream(new V4Stream().streamId("ABC123").streamType("IM")))));
    getPrivateBot().sendToConsumer(in);
    littleSleep();
    wireMockRule.verify(1, WireMock.postRequestedFor(urlPathMatching("/kore2")));
    wireMockRule.verify(1, WireMock.postRequestedFor(urlPathMatching("/agent/v4/stream/ABC123/message/create")));
}
Also used : V4Message(com.symphony.api.model.V4Message) V4Initiator(com.symphony.api.model.V4Initiator) V4MessageSent(com.symphony.api.model.V4MessageSent) V4Event(com.symphony.api.model.V4Event) V4User(com.symphony.api.model.V4User) V4Stream(com.symphony.api.model.V4Stream) V4Payload(com.symphony.api.model.V4Payload) Test(org.junit.jupiter.api.Test)

Example 10 with V4Stream

use of com.symphony.api.model.V4Stream in project spring-bot by finos.

the class BotIT method testSendMessageRoomWithSlash.

@Test
public void testSendMessageRoomWithSlash() {
    V4Event in = new V4Event().initiator(new V4Initiator().user(new V4User().email("rob@example.com").displayName("Rob Example").userId(2438923l))).payload(new V4Payload().messageSent(new V4MessageSent().message(new V4Message().message("<div>/hello</div>").data("{}").stream(new V4Stream().streamId("ABC123").streamType("ROOM")))));
    getPublicBot().sendToConsumer(in);
    littleSleep();
    wireMockRule.verify(1, WireMock.postRequestedFor(urlPathMatching("/kore")).withRequestBody(matching(".*\"message\":\\{\"text\":\"hello\"\\}.*")));
}
Also used : V4Message(com.symphony.api.model.V4Message) V4Initiator(com.symphony.api.model.V4Initiator) V4MessageSent(com.symphony.api.model.V4MessageSent) V4Event(com.symphony.api.model.V4Event) V4User(com.symphony.api.model.V4User) V4Stream(com.symphony.api.model.V4Stream) V4Payload(com.symphony.api.model.V4Payload) Test(org.junit.jupiter.api.Test)

Aggregations

V4Stream (com.symphony.api.model.V4Stream)10 V4Event (com.symphony.api.model.V4Event)9 V4Payload (com.symphony.api.model.V4Payload)9 V4User (com.symphony.api.model.V4User)9 Test (org.junit.jupiter.api.Test)9 V4Initiator (com.symphony.api.model.V4Initiator)7 V4MessageSent (com.symphony.api.model.V4MessageSent)7 V4Message (com.symphony.api.model.V4Message)6 V4SymphonyElementsAction (com.symphony.api.model.V4SymphonyElementsAction)2 EntityJson (org.finos.symphony.toolkit.json.EntityJson)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 V4RoomCreated (com.symphony.api.model.V4RoomCreated)1 V4RoomProperties (com.symphony.api.model.V4RoomProperties)1 V4UserJoinedRoom (com.symphony.api.model.V4UserJoinedRoom)1 Mention (com.symphony.user.Mention)1 UserId (com.symphony.user.UserId)1 IOException (java.io.IOException)1 Map (java.util.Map)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1