BotMill / fb-botmill

A Java framework for building bots on Facebook's Messenger Platform.
MIT License
72 stars 26 forks source link

Integration of Botmill with Spring-boot #127

Closed darrelRayen closed 7 years ago

darrelRayen commented 7 years ago

Is it possible to integrate botmill with spring-boot

alvin-reyes commented 7 years ago

Yes it is.

BotMill framework is just a java library. You can call the built in class load functions we have to load the bots on your Spring-Boot start up context.

//    load the botmill.properties config.
 ConfigurationUtils.loadConfigurationFile();

//    set the tokens
FbBotMillContext.getInstance().setup( ConfigurationUtils.getConfiguration().getProperty(FB_BOTMILL_PAGE_TOKEN),ConfigurationUtils.getConfiguration().getProperty(FB_BOTMILL_VALIDATION_TOKEN));

//    load the bots (@Bot)
ConfigurationUtils.loadBotDefinitions();
Manojjanaka commented 7 years ago

Hi,

I got everything setup and seems everything is working fine. I can see the request in the log also. But the Bot doesn't reply to any messages. Is there any other configuration that we need to do.

12:02:38.784 DEBUG [main][FbBotMillNetworkController] Confirmation from Facebook. Recipient ID: [null], Message ID: [null], Result Message: [success]
12:02:59.911 DEBUG [http-nio-8080-exec-1][FbBot] AbstractFbot - Start Initialize
12:02:59.911 DEBUG [http-nio-8080-exec-1][FbBot] AbstractFbot - End Initialize
12:02:59.911 INFO  [http-nio-8080-exec-1][BotMillServlet] BotMill servlet started.
12:02:59.927 DEBUG [http-nio-8080-exec-1][FbBotMillServlet] JSON input: {"object":"page","entry":[{"id":"1723442377696212","time":1499162574914,"messaging":[{"sender":{"id":"1328610440586613"},"recipient":{"id":"1723442377696212"},"timestamp":1499162574757,"message":{"mid":"mid.$cAAZFhUaSwZZjPlLHpVdDQ7ZYAO6p","seq":35602,"text":"hi"}}]}]}
12:03:24.559 DEBUG [http-nio-8080-exec-2][FbBotMillServlet] JSON input: {"object":"page","entry":[{"id":"1723442377696212","time":1499162604131,"messaging":[{"sender":{"id":"1375110925911070"},"recipient":{"id":"1723442377696212"},"timestamp":1499162603940,"message":{"mid":"mid.$cAAZFgVAy_e5jPlM5pFdDQ3wpZo1b","seq":226,"text":"Hi"}}]}]}
Manojjanaka commented 7 years ago

Hi, This got resolved when I updated the version to RC-03-snapshot. Thanks

alvin-reyes commented 7 years ago

Can you paste your method here? Did you pass the message envelope object?

On Tue, Jul 4, 2017 at 6:44 AM Manojjanaka notifications@github.com wrote:

Hi,

I got everything setup and seems everything is working fine. I can see the request in the log also. But the Bot doesn't reply to any messages. Is there any other configuration that we need to do.

12:02:38.784 DEBUG [main][FbBotMillNetworkController] Confirmation from Facebook. Recipient ID: [null], Message ID: [null], Result Message: [success] 12:02:59.911 DEBUG [http-nio-8080-exec-1][FbBot] AbstractFbot - Start Initialize 12:02:59.911 DEBUG [http-nio-8080-exec-1][FbBot] AbstractFbot - End Initialize 12:02:59.911 INFO [http-nio-8080-exec-1][BotMillServlet] BotMill servlet started. 12:02:59.927 DEBUG [http-nio-8080-exec-1][FbBotMillServlet] JSON input: {"object":"page","entry":[{"id":"1723442377696212","time":1499162574914,"messaging":[{"sender":{"id":"1328610440586613"},"recipient":{"id":"1723442377696212"},"timestamp":1499162574757,"message":{"mid":"mid.$cAAZFhUaSwZZjPlLHpVdDQ7ZYAO6p","seq":35602,"text":"hi"}}]}]} 12:03:24.559 DEBUG [http-nio-8080-exec-2][FbBotMillServlet] JSON input: {"object":"page","entry":[{"id":"1723442377696212","time":1499162604131,"messaging":[{"sender":{"id":"1375110925911070"},"recipient":{"id":"1723442377696212"},"timestamp":1499162603940,"message":{"mid":"mid.$cAAZFgVAy_e5jPlM5pFdDQ3wpZo1b","seq":226,"text":"Hi"}}]}]}

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/BotMill/fb-botmill/issues/127#issuecomment-312846657, or mute the thread https://github.com/notifications/unsubscribe-auth/AERYw48ObUlEqZvhw3NmueYs303mNU5Sks5sKheFgaJpZM4OKZ67 .

Manojjanaka commented 7 years ago

Actually what I did was, I added the FbBotMillServlet to the spring boot context by

 @Bean
    public ServletRegistrationBean dispatchServletRegistration() {

        ServletRegistrationBean registration = new ServletRegistrationBean(new FbBotMillServlet(), "/webhook");
        registration.setName(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
        return registration;

    }

And then I created the FbBot as follows

@Bot
public class MyBotClass extends FbBot {

    @FbBotMillController(eventType = FbBotMillEventType.MESSAGE_PATTERN, pattern = "(?i:hi)|(?i:hello)|(?i:hey)|(?i:good day)|(?i:home)")
    public void replyWithQuickReply(MessageEnvelope envelope) {
        reply(new AutoReply() {
            @Override
            public FbBotMillResponse createResponse(MessageEnvelope envelope) {
                return ReplyFactory.addTextMessageOnly("Text message with quick replies")
                        .addQuickReply("Quick reply 1", "Payload for quick reply 1").build(envelope);
            }
        });
    }
}

and used the 2.0.0-RC3-SNAPSHOT as the dependency.

You can find the sample project here