fb-messenger-clj is a Clojure library for the Facebook Messenger Bot API.
The goal of this library is to provide easy-to-use functions, well defined documentation & application examples so you can start with development and get results right away.
fb-messenger
is available as a Maven artifact from Clojars.
With Leiningen/Boot:
The Facebook Messenger Library is provided by the fb-messenger
namespace.
First, require the namespace needed (for example auth
) in the REPL:
(require '[fb-messenger.auth :as fb])
Or in your application:
(ns my-app.core
(:require [fb-messenger.auth :as fb]))
See how to set up a Facebook Messenger Bot in the Wiki.
Code examples:
-
Echo Bot Example using
prometheus-ai/fb-messenger-clj
-
Echo Bot Example ready for Heroku using
prometheus-ai/fb-messenger-clj
including live demo
Further Code Examples in Clojure:
- Facebook Messenger Bot in Clojure on Heroku
- Facebook Messenger Bot in Clojure on Google App Engine
- Facebook Messenger NLP Example in Clojure
- Chatfuel JSON API & Broadcasting API Example
- Extract Latitude & Longitude from Images
- Distance between two locations in Latitude & Longitude
- ClojureScript on the server side using Lumo
This library has the following functions:
Authentication (auth.clj)
(authenticate params)
Sending Messages (send.clj)
Send messages to users. (Send Message API Facebook Documentation)
Send Message Handler:
(send-message recipient-id message)
Examples using the text and video message templates from below:
(send-message recipient-id (text-message "Hello World"))
(send-message recipient-id (video-message [video-url]))
Available Message Templates (templates.clj)
Image:
(image-message [image-url])
Video:
(video-message [video-url])
Audio:
(audio-message [audio-url])
File:
(file-message [file-url])
Text:
(text-message [text])
Quick Replies:
(quick-replies-message [text quick-replies])
Button Template:
(button-template [text buttons])
Generic Template:
(generic-template [elements])
URL Button:
(url-button [title url])
Postback Button:
(postback-button [title postback])
Quick Reply Template:
(quick-reply [title payload *image-url*])
Location Quick Reply:
(location-quick-reply)
Upload File Attachment
You can send files by uploading them. (File Attachment Facebook Documentation)
(upload-attachment type url)
Set Facebook Messenger Profile:
Set your Bot's properties via the Facebook Messenger Profile API.
e.g. Persistent Menu, Get Started Button, Greeting Text, Domain Whitelisting, Account Linking, Payment Settings, Target Audience
(set-messenger-profile profile)
(get-user-profile psid)
To start using the Facebook Messenger Send/Receive service you'll need to setup a Facebook Page, Facebook App, create a Page Access Token and link the app to the page. We'll run through this step by step here.
- Use parinfer.
- Follow the Clojure Style Guide.
The use and distribution terms for this software are covered by the MIT License. You must not remove this notice, or any other, from this software.
Disclaimer: This software is not affiliated to Facebook or represents Facebook in any way.