Documentation ¶
Index ¶
- Constants
- func DefaultTransport() *http.Transport
- func IsLegacyLogin(login string) bool
- func StatusText(status Status) string
- type Conversation
- func (c *Conversation) Copy() *Conversation
- func (c *Conversation) NetworkID() string
- func (c *Conversation) NewMessage(id string) (*Message, error)
- func (c *Conversation) Refresh() error
- func (c *Conversation) RefreshThread() error
- func (c *Conversation) SendMessage(parts ...MessagePart) (time.Time, error)
- type EventMeta
- type LoginData
- type MemberRole
- type Message
- type MessageHandler
- type MessagePart
- type MessageType
- type MsgAction
- type MsgAnchor
- type MsgEmoji
- type MsgEmoticon
- type MsgFile
- type MsgMention
- type MsgQuote
- type MsgText
- type PollError
- type Resource
- type Session
- func (s *Session) APIURLRoot() string
- func (s *Session) Activate(timeout time.Duration) error
- func (s *Session) Client() *http.Client
- func (s *Session) ConversationFromNetworkID(networkID string) (*Conversation, error)
- func (s *Session) ConversationFromURL(resURL string) (*Conversation, error)
- func (s *Session) Do(req *http.Request) (*http.Response, error)
- func (s *Session) EnsureEndpoint(reAuth bool) error
- func (s *Session) IsLoggedIn() bool
- func (s *Session) IsPolling() bool
- func (s *Session) LoginData() LoginData
- func (s *Session) Logout() error
- func (s *Session) Me() *User
- func (s *Session) MessageFromConvURL(resURL string) (*Message, error)
- func (s *Session) NewConversation(id string, isPersonal bool) (*Conversation, error)
- func (s *Session) NewUser(username string) (*User, error)
- func (s *Session) OnNewMessage(handler MessageHandler)
- func (s *Session) OnThreadUpdate(handler ThreadUpdateHandler)
- func (s *Session) OnUserPresence(handler UserPresenceHandler)
- func (s *Session) Post(url string, contentType string, body io.Reader) (resp *http.Response, err error)
- func (s *Session) PostForm(url string, data url.Values) (resp *http.Response, err error)
- func (s *Session) SetStatus(status Status) (*UserPresence, error)
- func (s *Session) StartPolling() PollError
- func (s *Session) Status() (Status, error)
- func (s *Session) StopPolling()
- func (s *Session) UserFromContactsURL(resURL string) (*User, error)
- func (s *Session) UserFromNetworkID(networkID string) (*User, error)
- type Status
- type ThreadUpdateHandler
- type User
- type UserPresence
- type UserPresenceHandler
Constants ¶
const ( // TypeIDConversation is a prefix that conversation objects // have in IDs inside Skype network. A typical conversation // ID will look like this: 19:<hex-id>. TypeIDConversation = 19 // APIPathConversations gives a logged in user's conversations URL // when joined with APIPathMe. APIPathConversations = "/conversations" // APIPathThreads gives a conversation URL when joined // with conversation ID. APIPathThreads = "/threads" // APIPathMessages gives a conversation's messages URL // when joined with APIPathMe, APIPathConversations and // conversation's network ID. APIPathMessages = "/messages" )
const ( // LoginURL is the frst URL used in the login process. LoginURL = "https://login.skype.com/login" // LogoutURL is the frst URL used in the logout process. LogoutURL = "https://login.skype.com/logout" )
const ( // UserAgent is the user agent that this library uses when talking to Skype network. UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.106 Safari/537.36" // APIHost holds Skype network API host for non-legacy accounts (see IsLegacyLogin). This // is a default partial value, use Session.APIURLRoot to obtain actual API URL that the // session will use for its requests. APIHost = "client-s.gateway.messenger.live.com" // APIPathMe is the root of the logged in user's resources. APIPathMe = "/users/ME" // APIPathEndpoints gives a logged in user's endpoints URL // when joined with APIPathMe. APIPathEndpoints = "/endpoints" // APIPathSelf gives a logged in user's endpoint URL // when joined with APIPathMe and APIPathEndpoints. APIPathSelf = "/SELF" // APIPathActive gives an endpoint's activation URL // when joined with endpoint URL. APIPathActive = "/active" // APIPathPresence gives a logged in user's presence // URL when joined with APIPathMe and endpoint or contact URLs. APIPathPresence = "/presenceDocs/messagingService" // APIPathSubscriptions gives endpoint's subscriptions URL // when joined with endpoint URL. APIPathSubscriptions = "/subscriptions" // APIPathPoll gives a logged in user's first subscription polling URL // when joined with APIPathMe, APIPathEndpoints, APIPathSelf and APIPathSubscriptions. APIPathPoll = "/0/poll" )
const ( // APIPathContacts gives a logged in user's contacts URL // when joined with APIPathMe. APIPathContacts = "/contacts" )
const QuoteTimeFormat = "2006/01/02 15:04:05"
QuoteTimeFormat is used when 'flattening' quotes (quoting a quote).
const TypeIDUser = 8
TypeIDUser is a prefix that user objects have in IDs inside Skype network. A typical user ID in requests will look like 8:<username>.
Variables ¶
This section is empty.
Functions ¶
func DefaultTransport ¶
DefaultTransport returns a pointer to http.Transport that Login uses by default.
func IsLegacyLogin ¶
IsLegacyLogin checks if the Skype account with that login was created before MS took over. It determines that by checking '@outlook.com' suffix in the login.
func StatusText ¶
StatusText returns a text that is used to represent user presence status on the Skype network.
Types ¶
type Conversation ¶
type Conversation struct { Resource // IsPersonal indicates that this is a personal conversation // between two users. IsPersonal bool // Topic is a conversation topic. It is an empty string for // personal conversations. // // It appears that this is not always accurate for conversations // identified from new message event. To get the correct value // use RefreshThread. Topic string // Members is an array with conversation members. It is an array // containing all users in a group chat (including the one that // the Session uses) or a single element for the other user in // a personal conversation. Members map[*User]MemberRole }
Conversation represents any chat the user is part of. It might be a personal 1:1 conversation (see IsPersonal) or a group chat.
Note that Skype network also has a thread entity. Conversation struct contains data from both entities. Every group (but not personal) conversation has a matching thread. In Skype network, conversation is a thread from the logged-in user's perspective.
ID of this resource is a 32 character long hexadecimal string for group chats and the other user ID for personal chats.
func (*Conversation) Copy ¶
func (c *Conversation) Copy() *Conversation
Copy performs a deep copy of the Conversation. The new Conversation and all Skype Resources in its properties will refer to the same entities on the Skype network.
func (*Conversation) NetworkID ¶
func (c *Conversation) NetworkID() string
NetworkID returns a string that is used when specifying this resource in requests to Skype network. For Conversation, it looks like: 19:<hex-id>. For personal conversations, it is the same as the other user's NetworkID.
func (*Conversation) NewMessage ¶
func (c *Conversation) NewMessage(id string) (*Message, error)
NewMessage creates a new Message for a given username. You can use this function to later call Refresh on the resulting struct to retrieve information about arbitrary messages.
func (*Conversation) Refresh ¶
func (c *Conversation) Refresh() error
Refresh the information about this conversation. This will attempt to fill all the fields it can using the information from Skype network.
func (*Conversation) RefreshThread ¶
func (c *Conversation) RefreshThread() error
RefreshThread refreshes the information about the underlying thread. Updated properties: Topic, Members.
This operation only makes sense for non-personal (see IsPersonal) conversations, it will return error if used on a personal conversation.
func (*Conversation) SendMessage ¶
func (c *Conversation) SendMessage(parts ...MessagePart) (time.Time, error)
SendMessage constructs a message out of MessageParts and sends it to the conversation. It returns OriginalArrvialTime as reported by the Skype network.
type EventMeta ¶
type EventMeta struct { // Time is a timestamp that is associated with this event. Time time.Time // ResourceURL is a URL that can be used to access the resource in // this event. ResourceURL *url.URL }
EventMeta contains fields sent by Skype network with any event.
type LoginData ¶
LoginData holds various pieces of data received during the login process and endpoint creation.
This is useful if you want to perform actions that are not implemented in this library. Session.APIURLRoot function and APIPath* constants will help you with this as well.
type MemberRole ¶
type MemberRole uint8
MemberRole represents the conversation member role.
const ( // MemberRoleUser represents a User conversation member role. MemberRoleUser MemberRole = iota // MemberRoleAdmin represents an Admin conversation member role. MemberRoleAdmin )
type Message ¶
type Message struct { Resource // Type represents a message type (like message edit, or message removal). Check // MessageType enum for all possible values. Type MessageType // Sender is the User who sent the message (or performed an edit or removal). Sender *User // Conv is a conversation where the message was sent. Conv *Conversation // ComposeTime is a time that is sent in 'composetime' JSON field by the Skype network. ComposeTime time.Time // ClientID is a unique ID that is the same for message and all its modifications. You // can match MessageEdit and MessageRemoval messages with the appropriate MessageNews // using this field. ClientID, RawContent string // Content is a parsed content of the received message. It is an array of types // that implement MessagePart (implementing types are usually named 'Msg*'). Content []MessagePart }
Message represents a message event in the Skype network. A message event is one of the following: user typing, new message being sent, message being edited or message being removed. Use NewMessage to instantiate this struct.
func (*Message) Quote ¶
Quote is a convenience function for constructing a MsgQuote out of a Message.
func (*Message) Refresh ¶
Refresh the information about this message event. This will attempt to fill all the fields it can using the information from Skype network.
type MessageHandler ¶
MessageHandler is a function that handles message events.
type MessagePart ¶
type MessagePart interface { // Text gives XML-free representation. This is used // when constructing quotes. Text() string // Raw is a representation as Skype gives it and how it // expects to receive it. With any special characters // and XML tags. This is used when sending // outgoing messages. Raw() string }
MessagePart represents a part of Skype message, like an emoticon or text. Implementing structures represent specific type of message part.
type MessageType ¶
type MessageType uint8
MessageType represents a type of the message event.
const ( // MessageUnknown is a 'default' message type. Messages created // from bare IDs have this type. MessageUnknown MessageType = iota // MessageStartTyping indicates that the user started typing in // the conversation. Skype clients display a little pencil when they // receive that message. MessageStartTyping // MessageStopTyping indicates that the user stopped typing in // the conversation. Skype clients display a little pencil trying // to erase its writing when they receive that message. MessageStopTyping // MessageNew represents a simple message that the user has sent // into the conversation. MessageNew // MessageEdit is a message event that Skype network sends when // the user edits their previously sent message. MessageEdit // MessageRemoval is a message event that Skype network sends when // the user removes their previously sent message. MessageRemoval )
type MsgAction ¶
type MsgAction string
MsgAction represents a /me IRC-style action at the start of the message. Typically, this will be the first MessagePart in Content property. If it is, it means that the whole message was sent via /me. MsgAction is actually a string that contains display name of the user who created this action.
You can convert any string to an action part but clients will typically override it before rendering. The only use in actually using non-empty string is for the messages starting with it to look pretty in Skype Web that uses the same user as the session on which SendMessage was called.
func (MsgAction) Offset ¶
Offset returns a number that represents byte length of the value returned by Text.
This number needs to be submitted as part of outgoing message JSON for Skype network to recognize the message as /me action.
type MsgAnchor ¶
type MsgAnchor struct { // Href is the URL that the anchor opens when clicked Href, Content string }
MsgAnchor is a part of the message that mentions somebody. Create mentions with NewAnchor. Note that Skype network will automatically create anchors out of any text that is a valid a HTTP(S) URL when sending a message even if you don't create the anchor yourself.
func NewAnchor ¶
NewAnchor creates an anchor with the specified target URL. It sets the Content property to the same value.
func (MsgAnchor) Raw ¶
Raw returns string representation of an XML tag that denotes emoticon when sending or receiving messages. Example: <a href="http://example.com">Test User</at>.
type MsgEmoji ¶
type MsgEmoji struct{}
MsgEmoji represents part of the message that is a Skype emoji. In Skype clients, you cannot send anything in addition to an emoji in the same message, that restriction applies to this API too.
type MsgEmoticon ¶
type MsgEmoticon struct { // Type is an emoticon type. It specifies what icon will actually // be drawn in the client Type, Content string }
MsgEmoticon is a part of the message that is a Skype emoticon. Create emoticons with NewEmoticon.
func NewEmoticon ¶
func NewEmoticon(eType string) MsgEmoticon
NewEmoticon creates an emoticon message part given a type. Type is a string like 'laugh' or 'cool'.
func (MsgEmoticon) Raw ¶
func (e MsgEmoticon) Raw() string
Raw returns string representation of an XML tag that denotes emoticon when sending or receiving messages. Example: <ss type="laugh">:D</ss>.
type MsgMention ¶
type MsgMention struct { // Username is the username of the mentioned user. Same format // as User.ID Username, Content string }
MsgMention is a part of the message that mentions somebody. Create mentions with NewMention or User.Mention.
func NewMention ¶
func NewMention(username string) MsgMention
NewMention creates a mention of the provided username. It sets the Content property to the same value.
func (MsgMention) Raw ¶
func (m MsgMention) Raw() string
Raw returns string representation of an XML tag that denotes mention when sending or receiving messages. Example: <at id="8:test">Test User</at>.
type MsgQuote ¶
type MsgQuote struct { // Author is the User who originally sent the quoted // message or a part of message. Author *User // Timestamp is a time when the quoted content was sent. Timestamp time.Time // RawContent is a string that represents raw content of the original message. RawContent string // Content is a parsed content of the original message. It is an array of types // that implement MessagePart (implementing types are usually named 'Msg*'). Content []MessagePart }
MsgQuote represents part of the message that is a quote of some other message (or a part of it). It contains data about the time the original message was sent as well as who sent it.
Since it is a message part that represents other message, it shares RawContent and Content properties with Message.
Quotes are created with NewQuote or Message.Quote.
func NewQuote ¶
func NewQuote(author *User, timestamp time.Time, parts ...MessagePart) *MsgQuote
NewQuote creates a quote given an author, timestamp and MessageParts.
Quotes created this way will have their RawContent filled with concatenation of Raw representations of each MessagePart.
func (MsgQuote) Raw ¶
Raw constructs a small XML document that when sent to Skype network will be interpreted as quote of another message.
func (MsgQuote) Text ¶
Text returns a 'flattened' representation of a quote. It is intentionally not the same as flattened representation Skype client gives when quoting a quote because that is quite limited.
Quote content is prefixed with time (check QuoteTimeFormat) and author's DisplayName (or ID if not available). The newline is appended at the end.
type MsgText ¶
type MsgText string
MsgText represents plain text part of message. To instantiate it, you can simply convert a string like this: MsgText(str).
type PollError ¶
type PollError interface { error // Response returns HTTP response that was received during polling. Note // that its body will already be closed and content will be available via // separate Body function. // // If we couldn't complete or even start the HTTP poll request, // this is an nil pointer. Response() *http.Response // Body returns poll response body. // // If we couldn't complete or even start the HTTP poll request, // this is an empty string. Body() string // Chunk returns part of HTTP response body that caused the error. // It doesn't necessarily mean parsing error. // // If we couldn't complete or even start the HTTP poll request, // this is an empty string. // // If the wrong HTTP response code was received or the response body // couldn't be parsed, it's the same as Body. If some individual // event message couldn't be parsed or had some other error, it is the // respective event message. Chunk() string // PanicValue returns a value of a panic that occurred during event handler // execution. If there was a parsing error (i.e. we didn't get to the stage // of running event handlers), this is a nil interface. PanicValue() interface{} }
PollError is an interface for representing an error encountered while polling Skype network.
type Resource ¶
type Resource struct { // Sess contains a pointer to the Skype Session that owns the Resource. Since all // Skype Sessions connect to the same network, this field only determines // credentials that will be used when performing operations on that Resource. Sess *Session // ID of the Resource is a string that uniquely identifies the resource. It // is necessary (but may not be sufficient) for constructing various URLs // associated with this resource in Skype network. // // This string will look different for different types of resources, but will // never include type IDs (like TypeIDUser). ID string }
Resource represents a Resource in Skype network (like user or message). It contains fields that are required (but may not be sufficient) for bare representation of a Resource. This type is meant to be embedded into more specific types.
Most embedding structures (like User or Message) have Refresh method that fetches the full Resource representation from Skype network.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents a session in the Skype network. It holds all authentication data obtained during login precess and allows you to perform any action a web version of Skype is able to perform after logging in via login and password.
The Session itself is safe for concurrent use, but the objects you will receive when working with it are not.
func Login ¶
Login to Skype network using login and password. You can supply your own *http.Transport as the last argument to adjust various HTTP parameters for the resulting Session. Returns Skype Session you can use to perform actions as the given account.
The returned session does not store your supplied credentials but it will contain HTTP cookies and other tokens Skype network responds with during login process.
func (*Session) APIURLRoot ¶
APIURLRoot returns Skype network root API URL for a given session. This differs based on whether or not the account is legacy (see IsLegacyLogin).
Session will determine the URL it needs to use during login process and then will use it for all further communications.
func (*Session) Activate ¶
Activate is a keep-alive function. Calling this periodically (with a period that is less than timeout argument) is required to keep the endpoint available for polling if you are not currently polling.
Maximum value for a timeout is 5 minutes.
func (*Session) Client ¶
Client returns a pointer to the http.Client that the session uses for all its requests. This is useful if you want to adjust its parameters (like proxying or TLS configuration).
func (*Session) ConversationFromNetworkID ¶
func (s *Session) ConversationFromNetworkID(networkID string) (*Conversation, error)
ConversationFromNetworkID constructs a Conversation from network ID string that looks like: 19:<conversation-id>@thread.skype (group) or 8:<username> (personal).
func (*Session) ConversationFromURL ¶
func (s *Session) ConversationFromURL(resURL string) (*Conversation, error)
ConversationFromURL constructs a Conversation struct from the logged in user's conversations URL.
func (*Session) Do ¶
Do mimics http.Client.Do. Copies the given request, appends RegistrationToken header (if the session has it) and executes the request via session's HTTP client.
func (*Session) EnsureEndpoint ¶
EnsureEndpoint does several things to ensure the availability of the session's endpoint for immediate polling. Setting reAuth to true will also refresh your registration token using cookies obtained during login process.
You can use this if StartPolling returned some non-200 HTTP code to avoid creating the Session from scratch.
func (*Session) IsLoggedIn ¶
IsLoggedIn indicates whether or not a session is logged in.
A session is considered to be logged in if it has non-empty non-expired registration token.
Note that almost all Session actions can only be performed when the session is logged in. It is up to you to check that using this function if you are not sure about the state of the session.
func (*Session) LoginData ¶
LoginData returns login data struct that holds all tokens obtained throughout the Skype network login process and endpoint creation.
func (*Session) Me ¶
Me returns a pointer to copy of the logged in User. Be sure to store the returned pointer somewhere if you need persistence (e.g. for Refresh).
func (*Session) MessageFromConvURL ¶
MessageFromConvURL constructs a Message struct from the logged in user's messages for conversation URL.
func (*Session) NewConversation ¶
func (s *Session) NewConversation(id string, isPersonal bool) (*Conversation, error)
NewConversation creates a new Conversation for a given conversation ID (group) or user username (personal). You can use this function to later call Refresh on the resulting struct to retrieve information about arbitrary conversations.
func (*Session) NewUser ¶
NewUser creates a new User for a given username. You can use this function to later call Refresh on the resulting User to retrieve information about arbitrary users.
func (*Session) OnNewMessage ¶
func (s *Session) OnNewMessage(handler MessageHandler)
OnNewMessage attaches a message event handler to the session.
Note that your own messages and actions will also trigger this event so if you are replying to each new message caught here, an infinite loop will be triggered. To avoid it, check the Sender of the message against the Session's Me field.
func (*Session) OnThreadUpdate ¶
func (s *Session) OnThreadUpdate(handler ThreadUpdateHandler)
OnThreadUpdate attaches a thread update event handler to the session. Thread updates will be triggered, for example, when a member leaves a conversation.
func (*Session) OnUserPresence ¶
func (s *Session) OnUserPresence(handler UserPresenceHandler)
OnUserPresence attaches a user presence handler to the session.
func (*Session) Post ¶
func (s *Session) Post(url string, contentType string, body io.Reader) (resp *http.Response, err error)
Post mimics http.Client.Post. It uses Session.Do under the hood.
func (*Session) SetStatus ¶
func (s *Session) SetStatus(status Status) (*UserPresence, error)
SetStatus allows you to change the logged in user's status in the Skype network.
You can't use StatusOffline here for some reason.
func (*Session) StartPolling ¶
StartPolling starts polling the Skype network for events. If you don't call this function, none of your event handlers will ever be called.
This function blocks until polling is stopped. Polling is stopped on any error that occurs (like HTTP failure or parsing failure). Polling is also stopped if any event handler panics. The panic value is then returned as part of PollError.
Attempting to poll while already polling is also an error that is returned immediately. This error does not cancel polling. To check if the session polling is already underway, use IsPolling.
func (*Session) Status ¶
Status is a convenience function to get the logged in user's status from the Skype network.
func (*Session) StopPolling ¶
func (s *Session) StopPolling()
StopPolling stops the ongoing polling for a session. If the session is not polling, it simply returns instantly.
func (*Session) UserFromContactsURL ¶
UserFromContactsURL constructs a User from the logged in user's contacts URL.
type Status ¶
type Status uint8
Status is a Skype network user status (like Online or Do not disturb).
const ( // StatusOnline represents Online status. StatusOnline Status = iota // StatusAway represents Away status. StatusAway // StatusDND represents Do not disturb (Busy) status. StatusDND // StatusInvisible represents Invisible (Hidden) status. StatusInvisible // StatusOffline represents Offline status. StatusOffline )
func (Status) MarshalJSON ¶
MarshalJSON is needed for JSON conversion.
func (*Status) UnmarshalJSON ¶
UnmarshalJSON is needed for JSON conversion.
type ThreadUpdateHandler ¶
type ThreadUpdateHandler func(*Conversation, EventMeta)
ThreadUpdateHandler is a function that handles thread update events.
type User ¶
type User struct { Resource // DisplayName is a name that is visible in the Skype client's // main window as well as in conversations when the user sends // messages. DisplayName string }
User represents a user on the Skype network. Its ID is the user's username. For non-legacy accounts this will include 'live:' prefix.
func (*User) Copy ¶
Copy performs a deep copy of the User. The new User will refer to the same user on the Skype network.
func (*User) IsLegacy ¶
IsLegacy checks if the Skype user was created before MS took over. It determines that by checking 'live:' prefix in the username.
func (*User) Mention ¶
func (u *User) Mention() MsgMention
Mention constructs message part that mentions the user. You can use that to send outgoing messages mentioning users.
The Content property will be set to the user's DisplayName. If that is empty, a username will be used.
func (*User) NetworkID ¶
NetworkID returns a string that is used when specifying this resource in requests to Skype network. For User, it looks like: 8:<username>.
func (*User) Presence ¶
func (u *User) Presence() (*UserPresence, error)
Presence gets the UserPresence for this user.
func (*User) Refresh ¶
Refresh the information about this user. This will attempt to fill all the fields it can using the information from Skype network.
func (*User) SendMessage ¶
func (u *User) SendMessage(parts ...MessagePart) (time.Time, error)
SendMessage is a convenience method for sending a message to the given user. It calls Conversation.SendMessage under the hood.
type UserPresence ¶
type UserPresence struct { // User is a pointer to the user which this presence is for. User *User // Status represents user's online status. Status Status }
UserPresence contains information about user's online presence.
type UserPresenceHandler ¶
type UserPresenceHandler func(*UserPresence, EventMeta)
UserPresenceHandler is a function that handles user presence events.