Reputation: 15
I'm trying to make viber bot (public account) using java/spring. I succeed with setting webhook for the bot (by deploying it to heroku and making post request
{
"url":"https://my.host.com"
}
using Postman) and now I'm trying to receive messages from users. The problem is that I'm a newbie in using spring and don't actually know how to receive any viber events.
Here is my code (just checking if I can receive viber callbacks):
@RestController
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@RequestMapping
public String request(@RequestHeader("X-Viber-Content-Signature") String serverSideSignature) {
System.out.println("Here we go!");
System.out.println(serverSideSignature);
return "Hello world!";
}
}
However, this doesn't works. If I make request with required serverSideSignature
(example from documentation) using Postman, such as
{
"event":"message",
"timestamp":1457764197627,
"message_token":4912661846655238145,
"sender":{
"id":"01234567890A=",
"name":"John McClane",
"avatar":"http://avatar.example.com",
"country":"UK",
"language":"en",
"api_version":1
},
"message":{
"type":"text",
"text":"a message to the service",
"media":"http://example.com",
"location":{
"lat":50.76891,
"lon":6.11499
},
"tracking_data":"tracking data"
}
}
,
I can see an console output. But it does not work if I send message to bot (don't even get any information from logs). I guess the problem is that I do not understand properly how viber sends any information to my webhook, but maybe there is someone who can explain that for me? Thanks a lot.
P.S. Viber REST API documentation
Upvotes: 1
Views: 1854
Reputation: 83
@RequestMapping uses GET method by default and Viber sends a callback to a webhook using POST method. Try to change @RequestMapping to @PostMapping and of course, you should be sure that your webhook is set correctly and your URL has a valid and official SSL certificate from a trusted CA.
Upvotes: 1