-
Notifications
You must be signed in to change notification settings - Fork 247
/
directmessages.go
67 lines (58 loc) · 2.78 KB
/
directmessages.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
package anaconda
import (
"net/url"
"strconv"
)
func (a TwitterApi) GetDirectMessages(v url.Values) (messages []DirectMessage, err error) {
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/direct_messages.json", v, &messages, _GET, response_ch}
return messages, (<-response_ch).err
}
func (a TwitterApi) GetDirectMessagesSent(v url.Values) (messages []DirectMessage, err error) {
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/direct_messages/sent.json", v, &messages, _GET, response_ch}
return messages, (<-response_ch).err
}
func (a TwitterApi) GetDirectMessagesShow(v url.Values) (message DirectMessage, err error) {
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/direct_messages/show.json", v, &message, _GET, response_ch}
return message, (<-response_ch).err
}
// https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/new-message
func (a TwitterApi) PostDMToScreenName(text, screenName string) (message DirectMessage, err error) {
v := url.Values{}
v.Set("screen_name", screenName)
v.Set("text", text)
return a.postDirectMessagesImpl(v)
}
// https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/new-message
func (a TwitterApi) PostDMToUserId(text string, userId int64) (message DirectMessage, err error) {
v := url.Values{}
v.Set("user_id", strconv.FormatInt(userId, 10))
v.Set("text", text)
return a.postDirectMessagesImpl(v)
}
// DeleteDirectMessage will destroy (delete) the direct message with the specified ID.
// https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/delete-message
func (a TwitterApi) DeleteDirectMessage(id int64, includeEntities bool) (message DirectMessage, err error) {
v := url.Values{}
v.Set("id", strconv.FormatInt(id, 10))
v.Set("include_entities", strconv.FormatBool(includeEntities))
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/direct_messages/destroy.json", v, &message, _POST, response_ch}
return message, (<-response_ch).err
}
func (a TwitterApi) postDirectMessagesImpl(v url.Values) (message DirectMessage, err error) {
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/direct_messages/new.json", v, &message, _POST, response_ch}
return message, (<-response_ch).err
}
// IndicateTyping will create a typing indicator
// https://developer.twitter.com/en/docs/direct-messages/typing-indicator-and-read-receipts/api-reference/new-typing-indicator
func (a TwitterApi) IndicateTyping(id int64) (err error) {
v := url.Values{}
v.Set("recipient_id", strconv.FormatInt(id, 10))
response_ch := make(chan response)
a.queryQueue <- query{a.baseUrl + "/direct_messages/indicate_typing.json", v, nil, _POST, response_ch}
return (<-response_ch).err
}