Help us shape the future of Go! Take the 2026 Go Developer Survey

messenger

package module
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2018 License: MIT Imports: 11 Imported by: 2

README

FSM

Messenger

Messenger is a Facebook Messenger target for fsm.

Environment Variables

When using this target, you must set two environment variables:

MESSENGER_VERIFY_TOKEN=""
MESSENGER_ACCESS_TOKEN=""

Getting Started

Note: The environment variables above are assumed to be set in this example code:

package main

import (
	"net/http"

	"github.com/fsm/fsm"
	"github.com/fsm/messenger"
	"github.com/julienschmidt/httprouter"
)

func main() {
	router := &httprouter.Router{
		RedirectTrailingSlash:  true,
		RedirectFixedPath:      true,
		HandleMethodNotAllowed: true,
    }

	router.HandlerFunc(http.MethodGet, "/facebook", messenger.SetupWebhook)
    router.HandlerFunc(http.MethodPost, "/facebook", messenger.GetMessageReceivedWebhook(getStateMachine(), getStore()))

	http.ListenAndServe(":5000", router)
}

func getStateMachine() fsm.StateMachine {
	// ...
}

func getStore() fsm.Store {
	// ...
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMessageReceivedWebhook

func GetMessageReceivedWebhook(stateMachine fsm.StateMachine, store fsm.Store) func(http.ResponseWriter, *http.Request)

GetMessageReceivedWebhook is the webhook that facebook posts to when a message is received from a user.

This must be a POST request, and have the same URL as the GET request.

https://developers.facebook.com/docs/messenger-platform/getting-started/webhook-setup

func SetupWebhook

func SetupWebhook(w http.ResponseWriter, r *http.Request)

SetupWebhook adds support for the Messenger Platform's webhook verification to your webhook. This is required to ensure your webhook is authentic and working.

This must be a GET request, and have the same URL as the POST request.

https://developers.facebook.com/docs/messenger-platform/getting-started/webhook-setup

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL