• Stars
    star
    108
  • Rank 321,259 (Top 7 %)
  • Language
    Go
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

✉ïļ A GO SDK for Facebook's messenger-platform: https://developers.facebook.com/docs/messenger-platform

Messenger Platform Go SDK

Build Status Coverage Status

A Go SDK for the Facebook Messenger Platform.

Installation

go get gopkg.in/maciekmm/messenger-platform-go-sdk.v4

Usage

The main package has been named messenger for convenience.

Your first step is to create Messenger instance.

import "gopkg.in/maciekmm/messenger-platform-go-sdk.v4"

//...

messenger := &messenger.Messenger {
	VerifyToken: "VERIFY_TOKEN/optional",
	AppSecret: "APP_SECRET/optional",
	AccessToken: "PAGE_ACCESS_TOKEN",
	Debug: messenger.DebugAll, //All,Info,Warning
}

Parameters

  • VerifyToken is the token needed for a verification process facebook performs. It's only required once. Optional.
  • AppSecret is the Application Secret token. It's used for message integrity check. Optional.
  • AccessToken is required to send messages. You can find this token in your app developer dashboard under Messenger tab.
  • Debug is used for setting debug mode type as described on https://developers.facebook.com/docs/graph-api/using-graph-api#debugging. Optional.

The next step is to hook up the handler to your HTTP server.

//hook up
http.HandleFunc("/webhook", messenger.Handler)
//start the server
http.ListenAndServe(":5646", nil)

The next step is to subscribe to an event, to do that you have to hook up your own handler.

messenger.MessageReceived = MessageReceived

//...

func MessageReceived(event messenger.Event, opts messenger.MessageOpts, msg messenger.ReceivedMessage) {
//do stuff
}

Sending messages

Example

Check more examples in examples folder.

var mess = &messenger.Messenger{
	AccessToken: "ACCESS_TOKEN",
}

func main() {
	mess.MessageReceived = MessageReceived
	http.HandleFunc("/webhook", mess.Handler)
	log.Fatal(http.ListenAndServe(":5646", nil))
}

func MessageReceived(event messenger.Event, opts messenger.MessageOpts, msg messenger.ReceivedMessage) {
	profile, err := mess.GetProfile(opts.Sender.ID)
	if err != nil {
		fmt.Println(err)
		return
	}
	resp, err := mess.SendSimpleMessage(opts.Sender.ID, fmt.Sprintf("Hello, %s %s, %s", profile.FirstName, profile.LastName, msg.Text))
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("%+v", resp)
}

More Repositories

1

container-tabs-sidebar

Firefox addon aiming to utilize screen estate more efficiently by showing tabs in a sidebar grouped by privacy containers. Inspired by TreeStyleTab.
JavaScript
112
star
2

sitemap-generator

A highly concurrent Go solution to build sitemaps. Features CLI, proxy support, rate limiting, robots.txt compliant, url filtering and many other features.
Go
22
star
3

AntiAura

AntiAura (check aura) is a simple plugin that allows you to check if someone has killAura hack.
Java
16
star
4

go-steam-web

Logging in to steam via steamcommunity website.
Go
5
star
5

CurveAPI

Provides transparent API for popular game: CurveFever
Go
3
star
6

environment-agnostic-frontend-docker-image

HTML
2
star
7

advent-of-code-2015

Doing AdventOfCode.com challenge with added rule: different language every day.
Go
2
star
8

AntiAutoSoup

Anti auto souping plugin
Java
1
star
9

hackathon-uek-platforma-backend

💎 UEK Hackathon Entry Backend
Go
1
star
10

enroll-me-2-caldav-exporter

Simple and naive Caldav exporter for enroll-me system on IEiT faculty.
JavaScript
1
star
11

CurveSignatures

Generates fancy signatures based on CurveAPI :)
Go
1
star
12

origami

ðŸĶĒ step by step origami folding visualisator and simulator
Python
1
star
13

PhoneticTranscriptor

✒ïļ Transcript phonetic alphabet to language specific phones
Go
1
star
14

hackathon-hackheroes-sciana-placzu-backend

ðŸĨ Allows poles to seek for first available dates of appointments in treatment facilities. It solves the problem of very long waiting time by distributing patients across hospitals.
Go
1
star
15

advent-of-code-2019

🎄 2019 solutions for Advent of Code
Go
1
star
16

advent-of-code-2016

🎄 This repository contains solutions for 2016 edition of Advent of Code in Go language.
Go
1
star
17

dokanki

Convert properly structured documents (Google docs, DOC(x), HTML, PDF) to Anki flashcards
Python
1
star
18

cv

📃 Personal CV in LaTeX
TeX
1
star