rampatra / jbot

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

/webhook is not exposed #183

Closed theanilpaudel closed 4 years ago

theanilpaudel commented 4 years ago

Hi,

I am trying to implement a messenger bot in Spring Boot.

I have added JBot from maven

<dependency>
<groupId>me.ramswaroop.jbot</groupId>
<artifactId>jbot</artifactId>
<version>4.1.0</version>
</dependency>

I have enabled base package scan on the main class @SpringBootApplication(scanBasePackages = {"me.ramswaroop.jbot","com.zepling.nepsesim"})

Then I have a MessengerBot class like this

@JBot
@Profile("facebook")
public class MessengerBot extends Bot {

    @Value("${fbBotToken}")
    private String fbToken;

    @Value("${fbPageAccessToken}")
    private String pageAccessToken;

    @Override
    public String getFbToken() {
        return fbToken;
    }

    @Override
    public String getPageAccessToken() {
        return pageAccessToken;
    }
}

The pageAccessToken is taken from Messenger product.

I am using SpringSecurity and I am permitting /webhook The problem is, whenever I try to hit https://mydomain.com/webhook I get 404 not found. While also on the logcat during spring startup the endpoint /webhook is not printed and also I get The Callback URL or Verify Token couldn't be validated. Please verify the provided information or try again later. on Messenger.

rampatra commented 4 years ago

See this https://github.com/rampatra/jbot/blob/master/jbot/src/main/java/me/ramswaroop/jbot/core/facebook/Bot.java#L74 Make sure you're supplying all the necessary params.

I am not sure why this endpoint isn't getting registered as I haven't seen your code. But try out jbot-example and see if it registers there.

theanilpaudel commented 4 years ago

Hi @rampatra, thanks for the reply.

It was a silly mistake, I forgot to set the spring profile. So, if someone encounters this silly mistake in the future, don't forget to add spring.profiles.active=slack,facebook on your application.properties file

farubel commented 3 years ago

@theanilpaudel how to you solve the issue, It does not work for me. This is my pom.xml file

`<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>com.combank</groupId>
<artifactId>combankfbbot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>combankfbbot</name>
<description>Fb bot demo project for Commercial Bank</description>
<properties>
    <java.version>9</java.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.2.11</version>
    </dependency>

    <dependency>
        <groupId>me.ramswaroop.jbot</groupId>
        <artifactId>jbot</artifactId>
        <version>4.1.0</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

`

in the application.properties file , I added `# jbot spring.profiles.active=slack,facebook spring.jackson.property-naming-strategy=SNAKE_CASE logging.level.me.ramswaroop=DEBUG server.port=8081

slack integrations

slackApi=https://slack.com/api slackBotToken= slashCommandToken=

replace the below url with your slack webhook url

slackIncomingWebhookUrl=https://slack.com

fb bot

fbGraphApi=https://graph.facebook.com/v2.6/me fbBotToken=fb_token_for_jbot fbPageAccessToken= `

my main Spring Boot Application looks like this

`@SpringBootApplication(scanBasePackages = {"me.ramswaroop.jbot", "com.bank.bot"}) public class DemoApplication {

@Bean
public RestTemplate restTemplate() {
    return new RestTemplate();
}

/**
 * Entry point of the application. Run this method to start the sample bots,
 * but don't forget to add the correct tokens in application.properties file.
 *
 * @param args
 */
public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
}

}`

my Bot code

`import me.ramswaroop.jbot.core.common.EventType; import me.ramswaroop.jbot.core.common.JBot; import me.ramswaroop.jbot.core.facebook.Bot; import me.ramswaroop.jbot.core.facebook.models.*; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Profile;

@Profile("facebook") @JBot public class FbBot extends Bot {

/**
 * Set this property in {@code application.properties}.
 */
@Value("${fbBotToken}")
private String fbToken;

/**
 * Set this property in {@code application.properties}.
 */
@Value("${fbPageAccessToken}")
private String pageAccessToken;

@Override
public String getFbToken() {
    return fbToken;
}

@Override
public String getPageAccessToken() {
    return pageAccessToken;
}

}`

The problem is, whenever I try to hit https://mydomain.com/webhook I get 404 not found. While also on the logcat during spring startup the endpoint /webhook is not printed and also I get The Callback URL or Verify Token couldn't be validated. Please verify the provided information or try again later. on Messenger. (same problem like you)