-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdoc.go
112 lines (112 loc) · 3.42 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Package fbmsgr provides an API for interacting with
// Facebook Messenger.
//
// Authentication
//
// The first step is to create a new Messenger session.
// Do this as follows, replacing "USER" and "PASS" with
// your Facebook login credentials:
//
// sess, err := fbmsgr.Auth("USER", "PASS")
// if err != nil {
// // Handle login failure.
// }
//
// Once you are done with a session you have allocated,
// you should call Close() on it to clear any resources
// (e.g. goroutines) that it is using.
//
// Sending messages
//
// When sending a message, you specify a receiver by their
// FBID.
// The receiver may be another user, or it may be a group.
// For most methods related to message sending, there is
// one version of the method for a user and one for a
// group:
//
// sess.SendText("USER_FBID", "what's up?")
// sess.SendGroupText("GROUP_FBID", "what's up?")
//
// To send or retract a typing notification, you might do:
//
// sess.SendTyping("USER_FBID", true) // typing
// sess.SendTyping("USER_FBID", false) // stopped typing
// sess.SendGroupTyping("GROUP_FBID", true)
//
// To send an attachment such as an image or a video, you
// can do the following:
//
// f, err := os.Open("/path/to/image.png")
// if err != nil {
// // Handle failure.
// }
// defer f.Close()
// upload, err := sess.Upload("image.png", f)
// if err != nil {
// // Handle failure.
// }
// _, err = sess.SendAttachment("USER_ID", upload)
// // or sess.SendGroupAttachment("GROUP_ID", upload)
// if err != nil {
// // Handle failure.
// }
//
// Events
//
// It is easy to receive events such as incoming messages
// using the ReadEvent method:
//
// for {
// x, err := sess.ReadEvent()
// if err != nil {
// // Handle error.
// }
// if msg, ok := x.(fbmsgr.MessageEvent); ok {
// if msg.SenderFBID == sess.FBID() {
// // It is a message that we sent.
// // This allows us to see messages we send
// // from a different device.
// continue
// }
// fmt.Println("received message:", msg)
// if msg.GroupThread != "" {
// sess.SendReadReceipt(msg.GroupThread)
// } else {
// sess.SendReadReceipt(msg.OtherUser)
// }
// } else if typ, ok := x.(fbmsgr.TypingEvent); ok {
// fmt.Println("user is typing:", typ)
// } else if del, ok := x.(fbmsgr.DeleteMessageEvent); ok {
// fmt.Println("we deleted a message:", del)
// }
// }
//
// With the EventStream API, you can get more fine-grained
// control over how you receive events.
// For example, you can read the next minute's worth of
// events like so:
//
// stream := sess.EventStream()
// defer stream.Close()
// timeout := time.After(time.Minute)
// for {
// select {
// case evt := <-stream.Chan():
// // Process event here.
// case <-timeout:
// return
// }
// }
//
// You can also create multiple EventStreams and read from
// different streams in different places.
//
// Listing threads
//
// To list the threads (conversations) a user is in, you
// can use the Threads method to fetch a subset of threads
// at a time. You can also use the AllThreads method to
// fetch all the threads at once.
//
package fbmsgr