Tutorial: Building a Facebook bot with Vapor 3 and Swift, part I
You have to keep in mind that a Facebook bot is just an app which is handling messages for you. Inside add a function that will be responsible for receiving the messages from the Messenger platform:
Let’s go through this code step by step:
Don’t forget to add all missing routes inside the :
As you may have noticed, the function is not checking the source of the input, so anyone who knows the webhook address can send malicious requests and pretend to be a Messenger bot. Then create the class that conforms to the and the protocol:
Sending the message to the Facebook platform is pretty straightforward:
To use the don’t forget to register it as a inside the app configuration file :
Now let’s create two additional tests to fully test the second webhook endpoint.
Source: mikemikina.com