messenger

package module
v0.0.0-...-3e7edfb Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2017 License: MIT Imports: 21 Imported by: 0

README

messenger

Go Report Card GoDoc

A Go (golang) package that allows you to interact with Facebook chat/Messenger using an unofficial API ported from github.com/Schmavery/facebook-chat-api.

Usage

See the /examples directory for example usage.

License

messenger is licensed under the MIT license which can be found here.

Documentation

Overview

Package messenger allows you to interact with Facebook chat/Messenger using an unofficial API ported from https://github.com/Schmavery/facebook-chat-api.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLoggedOut = errors.New("messenger: (probably) logged out")
	ErrUnknown   = errors.New("messenger: unknown error from server")
)

A subset of possible errors returned by OnError

View Source
var (
	ErrLoginError      = errors.New("messenger: incorrect login credentials")
	ErrLoginCheckpoint = errors.New("messenger: login checkpoint")
)

Errors that are returned by Login.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Name string
	Data io.Reader
}

Attachment represents an attachment

type ListenError

type ListenError struct {
	Op  string
	Err error
}

ListenError is the type of error that will always be passed to OnError. It contains information about the operation that caused the error, and the actual underlying error.

func (ListenError) Error

func (l ListenError) Error() string

type Message

type Message struct {
	FromUserID  string
	Thread      Thread
	Body        string
	Attachments []Attachment
	MessageID   string
	// contains filtered or unexported fields
}

Message represents a message object.

type ParseError

type ParseError struct {
	// contains filtered or unexported fields
}

ParseError is returned if an error due to parsing occurs.

func (ParseError) Error

func (p ParseError) Error() string

Error returns the detailed parse error message.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session represents a Facebook session.

func NewSession

func NewSession() *Session

NewSession creates a new Facebook session.

func (*Session) AllUserProfileInfo

func (s *Session) AllUserProfileInfo() (map[string]UserProfile, error)

AllUserProfileInfo returns all the users' profiles in the session's friend list as a map indexed by the user's ID.

func (*Session) Close

func (s *Session) Close() error

Close stops and returns all listeners on the session.

func (*Session) ConnectToChat

func (s *Session) ConnectToChat() error

ConnectToChat connects the session to chat after you've successfully logged in.

func (*Session) DumpSession

func (s *Session) DumpSession() ([]byte, error)

DumpSession dumps the session (i.e. cookies) and returns it as a []byte. Note that if you restore the session, you may not need to login, but you must reconnect to chat.

func (*Session) Listen

func (s *Session) Listen()

Listen starts listening for events and messages from Facebook's chat servers and blocks.

func (*Session) Login

func (s *Session) Login(email, password string) error

Login logs the session in to a Facebook account.

func (*Session) MarkAsRead

func (s *Session) MarkAsRead(thread Thread) error

MarkAsRead marks the specified thread as read.

func (*Session) NewMessageWithThread

func (s *Session) NewMessageWithThread(thread Thread) *Message

NewMessageWithThread creates a new message for the given thread.

func (*Session) OnError

func (s *Session) OnError(handler func(err error))

OnError sets the handler for when an error during listening occurs.

func (*Session) OnMessage

func (s *Session) OnMessage(handler func(msg *Message))

OnMessage sets the handler for when a message is received.

Receiving attachments isn't supported yet.

func (*Session) OnRead

func (s *Session) OnRead(handler func(thread Thread, userID string))

OnRead sets the handler for when a message is read.

func (*Session) OnTyping

func (s *Session) OnTyping(handler func(thread Thread, userID string, typing bool))

OnTyping sets the handler when someone starts or stops typing.

func (*Session) RestoreSession

func (s *Session) RestoreSession(data []byte) error

RestoreSession restores the session (i.e. cookies) stored as a []byte back into the session. Note that you may not need to login again, but you must reconnect to chat.

func (*Session) SendMessage

func (s *Session) SendMessage(msg *Message) (string, error)

SendMessage sends the message to the session. Only the Thread, Body and Attachments fields are used for sending. The message ID and error is returned.

TODO: Sending does not support attachments yet.

func (*Session) SetTypingIndicator

func (s *Session) SetTypingIndicator(thread Thread, typing bool) error

SetTypingIndicator sets the typing indicator seen by members of the thread.

func (*Session) UserProfileInfo

func (s *Session) UserProfileInfo(userID string) (UserProfile, error)

UserProfileInfo returns the user's profile given their ID.

type Thread

type Thread struct {
	ThreadID string
	IsGroup  bool
}

Thread represents a message thread. If IsGroup is false, ThreadID is the other user's ID.

type UserProfile

type UserProfile struct {
	UserID    string `json:"id"`
	Name      string `json:"name"`
	FirstName string `json:"firstName"`
	Vanity    string `json:"vanity"`
	IsFriend  bool   `json:"is_friend"`
}

UserProfile represents the profile information for a user.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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