Documentation ¶
Overview ¶
Package groupme defines a client capable of executing API commands for the GroupMe chat service
Index ¶
- Constants
- func HTTPHandlerFunc(callbacks ...HTTPMessageCallback) http.HandlerFunc
- func HTTPStatusText(code int) string
- func ValidID(id string) bool
- type Attachment
- type Block
- type Bot
- type BotClient
- type ChangeOwnerRequest
- type ChangeOwnerResult
- type Chat
- type Client
- func (c *Client) AddMembers(ctx context.Context, groupID string, members ...*Member) (string, error)
- func (c *Client) AddMembersResults(ctx context.Context, groupID string, resultID string) ([]*Member, error)
- func (c *Client) BlockBetween(ctx context.Context, userID, otherUserID string) (bool, error)
- func (c *Client) ChangeGroupOwner(ctx context.Context, reqs ChangeOwnerRequest) (ChangeOwnerResult, error)
- func (c *Client) Close() error
- func (c *Client) CreateBlock(ctx context.Context, userID, otherUserID string) (*Block, error)
- func (c *Client) CreateBot(ctx context.Context, bot *Bot) (*Bot, error)
- func (c *Client) CreateDirectMessage(ctx context.Context, m *Message) (*Message, error)
- func (c *Client) CreateGroup(ctx context.Context, gs GroupSettings) (*Group, error)
- func (c *Client) CreateLike(ctx context.Context, conversationID, messageID string) error
- func (c *Client) CreateMessage(ctx context.Context, groupID string, m *Message) (*Message, error)
- func (c *Client) CreateSMSMode(ctx context.Context, duration int, registrationID *string) error
- func (c *Client) DeleteSMSMode(ctx context.Context) error
- func (c *Client) DestroyBot(ctx context.Context, botID string) error
- func (c *Client) DestroyGroup(ctx context.Context, groupID string) error
- func (c *Client) DestroyLike(ctx context.Context, conversationID, messageID string) error
- func (c *Client) FormerGroups(ctx context.Context) ([]*Group, error)
- func (c *Client) IndexBlock(ctx context.Context, userID string) ([]*Block, error)
- func (c *Client) IndexBots(ctx context.Context) ([]*Bot, error)
- func (c *Client) IndexChats(ctx context.Context, req *IndexChatsQuery) ([]*Chat, error)
- func (c *Client) IndexDirectMessages(ctx context.Context, otherUserID string, req *IndexDirectMessagesQuery) (IndexDirectMessagesResponse, error)
- func (c *Client) IndexGroups(ctx context.Context, req *GroupsQuery) ([]*Group, error)
- func (c *Client) IndexLeaderboard(ctx context.Context, groupID string, p period) ([]*Message, error)
- func (c *Client) IndexMessages(ctx context.Context, groupID string, req *IndexMessagesQuery) (IndexMessagesResponse, error)
- func (c *Client) JoinGroup(ctx context.Context, groupID string, shareToken string) (*Group, error)
- func (c *Client) MyHitsLeaderboard(ctx context.Context, groupID string) ([]*Message, error)
- func (c *Client) MyLikesLeaderboard(ctx context.Context, groupID string) ([]*Message, error)
- func (c *Client) MyUser(ctx context.Context) (*User, error)
- func (c *Client) RejoinGroup(ctx context.Context, groupID string) (*Group, error)
- func (c *Client) RemoveMember(ctx context.Context, groupID, membershipID string) error
- func (c *Client) ShowGroup(ctx context.Context, groupID string) (*Group, error)
- func (c *Client) Unblock(ctx context.Context, userID, otherUserID string) error
- func (c *Client) UpdateGroup(ctx context.Context, groupID string, gs GroupSettings) (*Group, error)
- func (c *Client) UpdateMember(ctx context.Context, groupID string, nickname string) (*Member, error)
- func (c *Client) UpdateMyUser(ctx context.Context, us UserSettings) (*User, error)
- func (c *Client) UploadPicture(ctx context.Context, img image.Image, encoding PictureEncoding) (PictureURL, error)
- type ClientOption
- type Group
- type GroupMessages
- type GroupSettings
- type GroupsQuery
- type HTTPMessageCallback
- type IndexChatsQuery
- type IndexDirectMessagesQuery
- type IndexDirectMessagesResponse
- type IndexMessagesQuery
- type IndexMessagesResponse
- type Member
- type Message
- type MessagePreview
- type Meta
- type PhoneNumber
- type PictureEncoding
- type PictureURL
- type Timestamp
- type User
- type UserSettings
Constants ¶
const ( ChangeOwnerOk changeOwnerStatusCode = "200" ChangeOwnerRequesterNewOwner changeOwnerStatusCode = "400" ChangeOwnerNotOwner changeOwnerStatusCode = "403" ChangeOwnerBadGroupOrOwner changeOwnerStatusCode = "404" ChangeOwnerBadRequest changeOwnerStatusCode = "405" )
Change owner Status Codes
const ( PictureEncodingPNG = "png" PictureEncodingJPEG = "jpeg" )
const ( SenderTypeUser senderType = "user" SenderTypeBot senderType = "bot" SenderTypeSystem senderType = "system" )
SenderType constants
const ( Mentions attachmentType = "mentions" Image attachmentType = "image" Location attachmentType = "location" Emoji attachmentType = "emoji" )
AttachmentType constants
const ( PeriodDay = "day" PeriodWeek = "week" PeriodMonth = "month" )
Define acceptable period values
const GroupMeAPIBase = "https://api.groupme.com/v3"
GroupMeAPIBase - Endpoints are added on to this to get the full URI. Overridable for testing
const GroupMeImageBase = "https://image.groupme.com"
Variables ¶
This section is empty.
Functions ¶
func HTTPHandlerFunc ¶ added in v0.3.0
func HTTPHandlerFunc(callbacks ...HTTPMessageCallback) http.HandlerFunc
HTTPHandlerFunc creates an http.HandlerFunc that executes callback functions on each received message. Function should be registered on an http.Handler route for use in a callback URL server.
func HTTPStatusText ¶ added in v0.3.0
StatusText returns a text for the HTTP status code (according to GroupMe). It returns the empty string if the code is unknown.
Types ¶
type Attachment ¶
type Attachment struct { Type attachmentType `json:"type,omitempty"` Loci [][]int `json:"loci,omitempty"` UserIDs []string `json:"user_ids,omitempty"` URL string `json:"url,omitempty"` Name string `json:"name,omitempty"` Latitude string `json:"lat,omitempty"` Longitude string `json:"lng,omitempty"` Placeholder string `json:"placeholder,omitempty"` Charmap [][]int `json:"charmap,omitempty"` }
Attachment is a GroupMe message attachment, returned in JSON API responses
func (*Attachment) String ¶
func (a *Attachment) String() string
type Block ¶
type Block struct { UserID string `json:"user_id,omitempty"` BlockedUserID string `json:"blocked_user_id,omitempty"` CreatedAT Timestamp `json:"created_at,omitempty"` }
Block is a GroupMe block between two users, direct messages are not allowed
type Bot ¶
type Bot struct { BotID string `json:"bot_id,omitempty"` GroupID string `json:"group_id,omitempty"` Name string `json:"name,omitempty"` AvatarURL string `json:"avatar_url,omitempty"` CallbackURL string `json:"callback_url,omitempty"` DMNotification bool `json:"dm_notification,omitempty"` }
Bot is a GroupMe bot, it is connected to a specific group which it can send messages to
type BotClient ¶ added in v0.3.0
type BotClient struct {
// contains filtered or unexported fields
}
Client posts bot messages
func NewBotClient ¶ added in v0.3.0
func NewBotClient(botID string, options ...ClientOption) *BotClient
NewBotClient creates a new GroupMe API Client to post bot messages
type ChangeOwnerRequest ¶
type ChangeOwnerRequest struct { // Required GroupID string `json:"group_id"` // Required. UserId of the new owner of the group // who must be an active member of the group OwnerID string `json:"owner_id"` }
ChangeOwnerRequest defines the new owner of a group
func (ChangeOwnerRequest) String ¶
func (r ChangeOwnerRequest) String() string
type ChangeOwnerResult ¶
type ChangeOwnerResult struct { GroupID string `json:"group_id"` // UserId of the new owner of the group who is // an active member of the group OwnerID string `json:"owner_id"` Status changeOwnerStatusCode `json:"status"` }
ChangeOwnerResult holds the status of the group owner change
func (ChangeOwnerResult) String ¶
func (r ChangeOwnerResult) String() string
type Chat ¶
type Chat struct { CreatedAt Timestamp `json:"created_at,omitempty"` UpdatedAt Timestamp `json:"updated_at,omitempty"` LastMessage *Message `json:"last_message,omitempty"` MessagesCount int `json:"messages_count,omitempty"` OtherUser User `json:"other_user,omitempty"` }
Chat is a GroupMe direct message conversation between two users, returned in JSON API responses
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client communicates with the GroupMe API to perform actions on the basic types, i.e. Listing, Creating, Destroying
func NewClient ¶
func NewClient(authToken string, options ...ClientOption) *Client
NewClient creates a new GroupMe API Client
func (*Client) AddMembers ¶
func (c *Client) AddMembers(ctx context.Context, groupID string, members ...*Member) (string, error)
AddMembers -
Add members to a group.
Multiple members can be added in a single request, and results are fetchedwith a separate call (since memberships are processed asynchronously). The response includes a results_id that's used in the results request.
In order to correlate request params with resulting memberships, GUIDs can be added to the members parameters. These GUIDs will be reflected in the membership JSON objects.
Parameters:
groupID - required, string See Member. Nickname - required One of the following identifiers must be used: UserID - string PhoneNumber - PhoneNumber(string) Email - string
func (*Client) AddMembersResults ¶
func (c *Client) AddMembersResults(ctx context.Context, groupID string, resultID string) ([]*Member, error)
AddMembersResults - Get the membership results from an add call.
Successfully created memberships will be returned, including any GUIDs that were sent up in the add request. If GUIDs were absent, they are filled in automatically. Failed memberships and invites are omitted.
Keep in mind that results are temporary -- they will only be available for 1 hour after the add request.
Parameters:
groupID - required, string resultID - required, string
func (*Client) BlockBetween ¶
BlockBetween - Asks if a block exists between you and another user id
func (*Client) ChangeGroupOwner ¶
func (c *Client) ChangeGroupOwner(ctx context.Context, reqs ChangeOwnerRequest) (ChangeOwnerResult, error)
ChangeGroupOwner - Change owner of requested groups.
This action is only available to the group creator.
Response is a result object which contain status field, the result of change owner action for the request
Parameters: See ChangeOwnerRequest
func (*Client) CreateBlock ¶
CreateBlock - Creates a block between you and the contact
func (*Client) CreateBot ¶
CreateBot - Create a bot. See the Bots Tutorial (https://dev.groupme.com/tutorials/bots) for a full walkthrough.
func (*Client) CreateDirectMessage ¶
CreateDirectMessage - Send a DM to another user
If you want to attach an image, you must first process it through our image service.
Attachments of type emoji rely on data from emoji PowerUps.
Clients use a placeholder character in the message text and specify a replacement charmap to substitute emoji characters
The character map is an array of arrays containing rune data ([[{pack_id,offset}],...]).
func (*Client) CreateLike ¶
CreateLike - Like a message.
func (*Client) CreateMessage ¶
CreateMessage - Send a message to a group
If you want to attach an image, you must first process it through our image service.
Attachments of type emoji rely on data from emoji PowerUps.
Clients use a placeholder character in the message text and specify a replacement charmap to substitute emoji characters
The character map is an array of arrays containing rune data ([[{pack_id,offset}],...]).
The placeholder should be a high-point/invisible UTF-8 character.
func (*Client) CreateSMSMode ¶
CreateSMSMode - Enables SMS mode for N hours, where N is at most 48. After N hours have elapsed, user will receive push notfications.
Parameters:
duration - required, integer registration_id - string; The push notification ID/token that should be suppressed during SMS mode. If this is omitted, both SMS and push notifications will be delivered to the device.
func (*Client) DestroyBot ¶
DestroyBot - Remove a bot that you have created
func (*Client) DestroyGroup ¶
DestroyGroup -
Disband a group ¶
This action is only available to the group creator ¶
Parameters:
groupID - required, ßstring
func (*Client) DestroyLike ¶
DestroyLike - Unlike a message.
func (*Client) IndexBlock ¶
IndexBlock - A list of contacts you have blocked. These people cannot DM you
func (*Client) IndexChats ¶
IndexChats - Returns a paginated list of direct message chats, or conversations, sorted by updated_at descending.
func (*Client) IndexDirectMessages ¶
func (c *Client) IndexDirectMessages(ctx context.Context, otherUserID string, req *IndexDirectMessagesQuery) (IndexDirectMessagesResponse, error)
IndexDirectMessages -
Fetch direct messages between two users.
DMs are returned in groups of 20, ordered by created_at descending.
If no messages are found (e.g. when filtering with since_id) we return code 304.
Note that for historical reasons, likes are returned as an array of user ids in the favorited_by key.
Parameters:
otherUserID - required, string; the other participant in the conversation. See IndexDirectMessagesQuery
func (*Client) IndexGroups ¶
IndexGroups -
List the authenticated user's active groups.
The response is paginated, with a default of 10 groups per page.
Please consider using of omit=memberships parameter. Not including member lists might significantly improve user experience of your app for users who are participating in huge groups.
Parameters: See GroupsQuery
func (*Client) IndexLeaderboard ¶
func (c *Client) IndexLeaderboard(ctx context.Context, groupID string, p period) ([]*Message, error)
IndexLeaderboard - A list of the liked messages in the group for a given period of time. Messages are ranked in order of number of likes.
func (*Client) IndexMessages ¶
func (c *Client) IndexMessages(ctx context.Context, groupID string, req *IndexMessagesQuery) (IndexMessagesResponse, error)
IndexMessages - Retrieves messages for a group. By default, messages are returned in groups of 20, ordered by created_at descending. This can be raised or lowered by passing a limit parameter, up to a maximum of 100 messages. Messages can be scanned by providing a message ID as either the before_id, since_id, or after_id parameter. If before_id is provided, then messages immediately preceding the given message will be returned, in descending order. This can be used to continually page back through a group's messages. The after_id parameter will return messages that immediately follow a given message, this time in ascending order (which makes it easy to pick off the last result for continued pagination). Finally, the since_id parameter also returns messages created after the given message, but it retrieves the most recent messages. For example, if more than twenty messages are created after the since_id message, using this parameter will omit the messages that immediately follow the given message. This is a bit counterintuitive, so take care. If no messages are found (e.g. when filtering with before_id) we return code 304. Note that for historical reasons, likes are returned as an array of user ids in the favorited_by key.
func (*Client) JoinGroup ¶
JoinGroup -
Join a shared group ¶
Parameters:
groupID - required, string shareToken - required, string
func (*Client) MyHitsLeaderboard ¶
MyHitsLeaderboard -
A list of messages you have liked. Messages are returned in reverse chrono-order. Note that the payload includes a liked_at timestamp in ISO-8601 format.
Parameters:
groupID - required, string
func (*Client) MyLikesLeaderboard ¶
MyLikesLeaderboard -
A list of messages you have liked. Messages are returned in reverse chrono-order. Note that the payload includes a liked_at timestamp in ISO-8601 format.
Parameters:
groupID - required, string
func (*Client) RejoinGroup ¶
RejoinGroup -
Rejoin a group. Only works if you previously removed yourself.
Parameters:
groupID - required, string
func (*Client) RemoveMember ¶
RemoveMember -
Remove a member (or yourself) from a group.
Note: The creator of the group cannot be removed or exit.
Parameters:
groupID - required, string membershipID - required, string. Not the same as userID
func (*Client) ShowGroup ¶
ShowGroup -
Loads a specific group.
Parameters:
groupID - required, string
func (*Client) UpdateGroup ¶
UpdateGroup -
Update a group after creation ¶
Parameters:
groupID - required, string See GroupSettings
func (*Client) UpdateMember ¶
func (c *Client) UpdateMember(ctx context.Context, groupID string, nickname string) (*Member, error)
UpdateMember -
Update your nickname in a group. The nickname must be between 1 and 50 characters.
func (*Client) UpdateMyUser ¶
UpdateMyUser -
Update attributes about your own account ¶
Parameters: See UserSettings
func (*Client) UploadPicture ¶ added in v0.3.0
func (c *Client) UploadPicture(ctx context.Context, img image.Image, encoding PictureEncoding) (PictureURL, error)
UploadPicture posts an image to the GroupMe image service. Accepts either PNG or JPEG. Returns URLs to the uploaded image to be used in messages or avatars.
type ClientOption ¶ added in v0.3.0
type ClientOption func(client *client)
func WithHTTPClient ¶ added in v0.3.0
func WithHTTPClient(httpClient *http.Client) ClientOption
type Group ¶
type Group struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` // Type of group (private|public) Type string `json:"type,omitempty"` Description string `json:"description,omitempty"` ImageURL string `json:"image_url,omitempty"` CreatorUserID string `json:"creator_user_id,omitempty"` CreatedAt Timestamp `json:"created_at,omitempty"` UpdatedAt Timestamp `json:"updated_at,omitempty"` Members []*Member `json:"members,omitempty"` Messages GroupMessages `json:"messages,omitempty"` }
Group is a GroupMe group, returned in JSON API responses
func (*Group) GetMemberByNickname ¶
GetMemberByNickname gets the group member by their Nickname, nil if no member matches
func (*Group) GetMemberByUserID ¶
GetMemberByUserID gets the group member by their UserID, nil if no member matches
type GroupMessages ¶
type GroupMessages struct { Count uint `json:"count,omitempty"` LastMessageID string `json:"last_message_id,omitempty"` LastMessageCreatedAt Timestamp `json:"last_message_created_at,omitempty"` Preview MessagePreview `json:"preview,omitempty"` }
GroupMessages is a Group field, only returned in Group JSON API responses
type GroupSettings ¶
type GroupSettings struct { // Required. Primary name of the group. Maximum 140 characters Name string `json:"name"` // A subheading for the group. Maximum 255 characters Description string `json:"description"` // GroupMe Image Service URL ImageURL string `json:"image_url"` // Defaults false. If true, disables notifications for all members. // Documented for use only for UpdateGroup OfficeMode bool `json:"office_mode"` // Anyone with the URL can join the group Share bool `json:"share"` }
GroupSettings is the settings for a group, used by CreateGroup and UpdateGroup
func (GroupSettings) String ¶
func (gss GroupSettings) String() string
type GroupsQuery ¶
type GroupsQuery struct { // Fetch a particular page of results. Defaults to 1. Page int `json:"page"` // Define page size. Defaults to 10. PerPage int `json:"per_page"` // Comma separated list of data to omit from output. // Currently supported value is only "memberships". // If used then response will contain empty (null) members field. Omit string `json:"omit"` }
GroupsQuery defines optional URL parameters for IndexGroups
func (GroupsQuery) String ¶
func (q GroupsQuery) String() string
type HTTPMessageCallback ¶ added in v0.3.0
type HTTPMessageCallback func(Message)
HTTPMessageCallback is a function that acts on new messages sent from the GroupMe server to a callback URL.
type IndexChatsQuery ¶
type IndexChatsQuery struct { // Page Number Page int `json:"page"` // Number of chats per page PerPage int `json:"per_page"` }
IndexChatsQuery defines the optional URL parameters for IndexChats
type IndexDirectMessagesQuery ¶
type IndexDirectMessagesQuery struct { // Returns 20 messages created before the given message ID BeforeID string `json:"before_id"` // Returns 20 messages created after the given message ID SinceID string `json:"since_id"` }
IndexDirectMessagesQuery defines the optional URL parameters for IndexDirectMessages
func (IndexDirectMessagesQuery) String ¶
func (q IndexDirectMessagesQuery) String() string
type IndexDirectMessagesResponse ¶
type IndexDirectMessagesResponse struct { Count int `json:"count"` Messages []*Message `json:"direct_messages"` }
IndexDirectMessagesResponse contains the count and set of messages returned by the IndexDirectMessages API request
func (IndexDirectMessagesResponse) String ¶
func (r IndexDirectMessagesResponse) String() string
type IndexMessagesQuery ¶
type IndexMessagesQuery struct { // Returns messages created before the given message ID BeforeID string // Returns most recent messages created after the given message ID SinceID string // Returns messages created immediately after the given message ID AfterID string // Number of messages returned. Default is 20. Max is 100. Limit int }
IndexMessagesQuery defines the optional URL parameters for IndexMessages
func (IndexMessagesQuery) String ¶
func (q IndexMessagesQuery) String() string
type IndexMessagesResponse ¶
type IndexMessagesResponse struct { Count int `json:"count"` Messages []*Message `json:"messages"` }
IndexMessagesResponse contains the count and set of messages returned by the IndexMessages API request
func (IndexMessagesResponse) String ¶
func (r IndexMessagesResponse) String() string
type Member ¶
type Member struct { ID string `json:"id,omitempty"` UserID string `json:"user_id,omitempty"` Nickname string `json:"nickname,omitempty"` Muted bool `json:"muted,omitempty"` ImageURL string `json:"image_url,omitempty"` AutoKicked bool `json:"autokicked,omitempty"` AppInstalled bool `json:"app_installed,omitempty"` GUID string `json:"guid,omitempty"` PhoneNumber string `json:"phone_number,omitempty"` // Only used when searching for the member to add to a group. Email string `json:"email,omitempty"` // Only used when searching for the member to add to a group. }
Member is a GroupMe group member, returned in JSON API responses
type Message ¶
type Message struct { ID string `json:"id,omitempty"` SourceGUID string `json:"source_guid,omitempty"` CreatedAt Timestamp `json:"created_at,omitempty"` GroupID string `json:"group_id,omitempty"` UserID string `json:"user_id,omitempty"` BotID string `json:"bot_id,omitempty"` SenderID string `json:"sender_id,omitempty"` SenderType senderType `json:"sender_type,omitempty"` System bool `json:"system,omitempty"` Name string `json:"name,omitempty"` RecipientID string `json:"recipient_id,omitempty"` ConversationID string `json:"conversation_id,omitempty"` AvatarURL string `json:"avatar_url,omitempty"` // Maximum length of 1000 characters Text string `json:"text,omitempty"` // Must be an image service URL (i.groupme.com) ImageURL string `json:"image_url,omitempty"` FavoritedBy []string `json:"favorited_by,omitempty"` Attachments []*Attachment `json:"attachments,omitempty"` }
Message is a GroupMe group message, returned in JSON API responses
type MessagePreview ¶
type MessagePreview struct { Nickname string `json:"nickname,omitempty"` Text string `json:"text,omitempty"` ImageURL string `json:"image_url,omitempty"` Attachments []*Attachment `json:"attachments,omitempty"` }
MessagePreview is a GroupMessages field, only returned in Group JSON API responses. Abbreviated form of Message type
type Meta ¶
Meta is the error type returned in the GroupMe response. Meant for clients that can't read HTTP status codes
type PhoneNumber ¶
type PhoneNumber string
PhoneNumber is the country code plus the number of the user
func (PhoneNumber) String ¶
func (pn PhoneNumber) String() string
func (PhoneNumber) Valid ¶
func (pn PhoneNumber) Valid() bool
Valid checks if the Phone Number string is numeric
type PictureEncoding ¶ added in v0.3.0
type PictureEncoding string
PictureEncoding specifies the encoding and Content-Type for the image upload.
type PictureURL ¶ added in v0.3.0
PictureURL contains URLS to an uploaded picture as well as the various thumbnails provided by GroupMe.
type Timestamp ¶
type Timestamp uint64
Timestamp is the number of seconds since the UNIX epoch
type User ¶
type User struct { ID string `json:"id,omitempty"` PhoneNumber PhoneNumber `json:"phone_number,omitempty"` ImageURL string `json:"image_url,omitempty"` Name string `json:"name,omitempty"` CreatedAt Timestamp `json:"created_at,omitempty"` UpdatedAt Timestamp `json:"updated_at,omitempty"` AvatarURL string `json:"avatar_url,omitempty"` Email string `json:"email,omitempty"` SMS bool `json:"sms,omitempty"` }
User is a GroupMe user, returned in JSON API responses
type UserSettings ¶
type UserSettings struct { // URL to valid JPG/PNG/GIF image. URL will be converted into // an image service link (https://i.groupme.com/....) AvatarURL string `json:"avatar_url"` // Name must be of the form FirstName LastName Name string `json:"name"` // Email address. Must be in name@domain.com form Email string `json:"email"` ZipCode string `json:"zip_code"` }
UserSettings are the settings for a GroupMe user