rampatra / jbot

Make Slack and Facebook Bots in Java.
GNU General Public License v3.0
1.2k stars 352 forks source link

conversation is not invoked on "setup meeting" #163

Open rajeshbtlit opened 4 years ago

rajeshbtlit commented 4 years ago

Thanks for your efforts, I am trying to use the start conversation , when we type "start meeting" the @Controller(pattern = "(setup meeting)", next = "confirmTiming") public void setupMeeting(WebSocketSession session, Event event) { is not invoked .

But
@Controller(events = {EventType.DIRECT_MENTION, EventType.DIRECT_MESSAGE}) public void onReceiveDM(WebSocketSession session, Event event) { is invoked.

Could you pease help.

Thanks in advance

Ronin3502 commented 4 years ago

The main reason the problem occurred since the condition is always true, and the type of event would be set as DIRECT_MESSAGE ( I don't know why : ( ,

So, I change the eventType in SlackBot.java .

I am not sure if my method towards this issue is proper. the following are the modifications on Slackbot.java: First, I added "events = EventType.DIRECT_MESSAGE" to each collector in the conversation. Second, I added some text check in each function.

The code of the conversation about setup meeting is like the following:

    @Controller(events = EventType.DIRECT_MESSAGE, pattern = "(setup meeting)", next = "confirmTiming")
    public void setupMeeting(WebSocketSession session, Event event) {
        if(event.getText().contains("meeting")){
            startConversation(event, "confirmTiming");   // start conversation
            reply(session, event, "Cool! At what time (ex. 15:30) do you want me to set up the meeting?");
        }
    }

    /**
     * This method will be invoked after {@link SlackBot#setupMeeting(WebSocketSession, Event)}.
     *
     * @param session
     * @param event
     */
    @Controller(events = EventType.DIRECT_MESSAGE, next = "askTimeForMeeting")
    public void confirmTiming(WebSocketSession session, Event event) {
        if(event.getText().contains(":")) {
            reply(session, event, "Your meeting is set at " + event.getText() +
                    ". Would you like to repeat it tomorrow?");
            nextConversation(event);    // jump to next question in conversation
        }
    }

    /**
     * This method will be invoked after {@link SlackBot#confirmTiming(WebSocketSession, Event)}.
     *
     * @param session
     * @param event
     */
    @Controller(events = EventType.DIRECT_MESSAGE, next = "askWhetherToRepeat")
    public void askTimeForMeeting(WebSocketSession session, Event event) {
        if (event.getText().contains("yes")) {
            reply(session, event, "Okay. Would you like me to set a reminder for you?");
            nextConversation(event);    // jump to next question in conversation  
        } else if(event.getText().contains("no")) {
            reply(session, event, "No problem. You can always schedule one with 'setup meeting' command.");
            stopConversation(event);    // stop conversation only if user says no
        }
    }

    /**
     * This method will be invoked after {@link SlackBot#askTimeForMeeting(WebSocketSession, Event)}.
     *
     * @param session
     * @param event
     */
    @Controller(events = EventType.DIRECT_MESSAGE)
    public void askWhetherToRepeat(WebSocketSession session, Event event) {
        if (event.getText().contains("yes")) {
            reply(session, event, "Great! I will remind you tomorrow before the meeting.");
        } else if(event.getText().contains("no")){
            reply(session, event, "Okay, don't forget to attend the meeting tomorrow :)");
        }
        stopConversation(event);    // stop conversation
    }

Hope my code can satisfy your expectation.