Skip to content

Sending messages

Allan Berger edited this page Nov 17, 2017 · 12 revisions

To respond to users using your bot, you can use the send-message function.

Usage of send-message

To send a message to a facebook user, you can use the following function:

(fb-messenger.send/send-message "recipient-id" (text-message "text") "token")

Replace the token with the page access token you received from facebook and the recipient-id with the id of the user you want to send the message to. Most likely you'll send a message in response to a message you received. The received message contains the recipient-id.

You can also configure the base-url and the token once and only pass the other two parameters to the send-message function:

(fb-messenger.send/set-base-url! "https://graph.facebook.com/v2.6")
(fb-messenger.send/set-page-access-token! "token")
(fb-messenger.send/send-message "recipient-id" (text-message "text"))

Note on fb-messenger.send/set-base-url!:

This library uses the "https://graph.facebook.com/v2.6" as a default for the base-url, so you do not need to set it manually if you intend to use this version of the facebook graph API.