Xend v0.6.1 Xend

Wrapper for Facebook's Send API This module defines functions for each type of message supported by the API: text, attachment and sender action.

Usage

Add xend as a dependency in your mix.exs:

defp deps do [ {:xend, "~> 0.5.0"} ] end

Add your facebook's page access token to your configuration for xend:

config :xend, fb_page_access_token: System.get_env("FB_PAGE_ACCESS_TOKEN")

Notification types

text/3, text/4 and attachment/3 functions receive as a last argument a notification type, which can be: "REGULAR", "SILENT_PUSH", "NO_PUSH". Refer to the Send API documentation for more information on notification types.

Summary

Functions

Sends a sender action which can be one of the following

Send a text message with predefined replies included aka quick replies

Types

predefined_replies()
response()
response :: {integer, any} | any

Functions

action(recipient_id, action)
action(String.t, atom) :: response

Sends a sender action which can be one of the following:

  • mark_seen: marks the message as seen
  • typing_on: triggers typing animation
  • typing_off: stops typing animatioon

Example

Xend.action("USER_ID", :mark_seen) Xend.action("USER_ID", :typing_on) Xend.action("USER_ID", :typing_off)

See https://developers.facebook.com/docs/messenger-platform/send-api-reference/sender-actions for more information

attachment(recipient_id, attachment, notification_type)
attachment(String.t, map, String.t) :: response

Send an attachment.

Example

attachment = %{ type: "image", payload: %{ url: "https://petersapparel.parseapp.com/img/shirt.png" } } Xend.attachment("USER_ID", attachment, "REGULAR")

See https://developers.facebook.com/docs/messenger-platform/send-api-reference for more info on attachments

text(recipient_id, text, notification_type)

Send a text message

Example

Xend.text("USER_ID", "Hello World", "REGULAR")

text(recipient_id, text, quick_replies, notification_type)

Send a text message with predefined replies included aka quick replies.

Example

quick_replies = [%{content_type: "text", title: "Yes", payload: ""}, %{content_type: "text", title: "No", payload: ""}] Xend.text("USER_ID", "Do you want ketchup with your order?", quick_replies, "REGULAR")

See https://developers.facebook.com/docs/messenger-platform/send-api-reference/quick-replies for more information on quick replies