MyNixOS website logo
Description

High-level bindings to Facebook Messenger Platform API.

Please see README.md

FBMessenger API

Build Status Hackage Hackage Dependencies Haskell Programming Language BSD3 License

High-level bindings to the Messenger Platform API based on servant library. We try to maintain the overall structure compatible with telegram-api.

There was an incongruence between the spec and the actual serialization of the webhook requests that became apparent when testing an actual messenger bot. For this reason you should use only versions of the library that are >= 0.1.1!

This library is alpha software and the API design could change to improve composability, ergonomicity and ease of use. We recommend using stack for dealing with this library (you will need to add it to the extra-deps in stack.yaml).

NOTE (1.6.2016): the WelcomeMessageSendAPI recently changed. The Platform no-longer accepts any welcome message api-wise (only a custom payload is now allowed). The library will be updated to reflect this change as soon as I can (otherwise you are welcome to submit a PR). To setup/modify the Welcome Message you have to use the online interface.

Usage

Before being able to test and use the bot, you will need to verify your key. The example app in example-app/example.hs contains a servant server that implements the verification and a trivial echo-server. You can run it with

VERIFY_TOKEN="your_token_goes_here" stack exec example

and pass it some data (here assuming you have httpie installed)

http get 'localhost:3000/webhook/?hub.verify_token=your_token_goes_here&hub.challenge=test'
http post :3000/webhook < test-files/wsTextMessageRequest.json

Otherwise run stack ghci then copy and paste the following

:m +Network.HTTP.Client
:m +Network.HTTP.Client.TLS
:m +Data.Text

let token = Token $ Data.Text.pack "your_token_goes_here"
let manager = newManager tlsManagerSettings
manager >>= \m -> subscribedApps $ Just token m

You should get a positive response or (in case of inactive token):

Left (FailureResponse {responseStatus = Status {statusCode = 400, statusMessage = "Bad Request"}, responseContentType = application/json, responseBody = "{\"error\":{\"message\":\"Invalid OAuth access token.\",\"type\":\"OAuthException\",\"code\":190,\"fbtrace_id\":\"ESxHmUos2B+\"}}"})

Contribution

  1. Fork repository
  2. Do some changes
  3. Create pull request
  4. Wait for CI build and review

You can use stack to build the project

stack build

To run tests

stack test

TODO

  • Tests for the network part of the api (hard, requires a bot setted up and permanently running just for the tests)
  • Check if assumption on https://github.com/mseri/fbmessenger-api-hs/blob/master/src/Web/FBMessenger/API/Bot/WebhookAPI.hs#L99 is safe
  • Cleanup Webhooks API Requests and add higher level helpers.
Metadata

Version

0.1.2.1

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows