tdclient

package module
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: MIT Imports: 20 Imported by: 1

README

Codecov coverage build codecov

tdclient

Simple client library.

Feedback

Join team: http://tada.team/apitalks

Example
package main

import (
	"fmt"
	"github.com/tada-team/tdclient"
	"github.com/tada-team/tdproto/tdapi"
)

func main() {
    session, err := tdclient.NewSession("https://web.tada.team")
    if err != nil {
       panic(err)
    }

    // Create new bot (/newbot command) or use examples/smsauth to get own account token
    session.SetToken("YOUR_TOKEN")

    // How to see team_uid: https://web.tada.team/{team_uid}/chats/{chat_jid}
    teamUid := "YOUR_TEAM_UID" 
	
    // show all requests/responses
    session.SetVerbose(true)
 
    // Check connection
    if err := session.Ping(); err != nil {
        panic(err)
    }
    
    // Invite new member to your team
    phone := "+70001234567"
    contact, err := session.AddContact(teamUid, phone)
    if err != nil {
        panic(err)
    }
    fmt.Println("contact created:", contact.Jid)
    
    // Send hello to direct
    msg, err := session.SendPlaintextMessage(teamUid, contact.Jid, "Hi there!") 
    fmt.Println("message sent at:", msg.Created)
    
    // Create new task. All Fields: https://github.com/tada-team/tdproto/blob/master/tdapi/task.go
    taskChat, err := session.CreateTask(teamUid, tdapi.Task{
        Description: "do it, do it now",
        Assignee:    contact.Jid,
        Public:      true, // task visible for all team members
    }) 
    fmt.Println("task created:", taskChat.Jid)
}

Snippets

Get server version
go run examples/serverinfo/main.go
go run examples/serverinfo/main.go -verbose
go run examples/serverinfo/main.go -verbose -server https://demo.tada.team

Any example have -verbose and -server options. Default server value is https://web.tada.team.

Authorization token

Some examples need authorization token. You have two options:

Bot token

Create bot by typing /newbot <BOTNAME> command in @TadaBot direct chat. Allowed for team admin only.

Token from your personal account

For server with sms authorization:

go run examples/smsauth/main.go

For server with Active Directory authorization:

go run examples/passwordauth/main.go
Contacts
go run examples/contacts/main.go -team <team uid> -token <token>
Messaging

Using websockets:

go run examples/send-message-ws/main.go -team <team uid> -token <token> -chat <chat jid> -message <message text>

or

Using http API only:

go run examples/send-message/main.go -team <team uid> -token <token> -chat <chat jid> -message <message text>

How to get team uid and chat jid:

https://demo.tada.team/dbd248d7-25c2-4e8f-a23a-99baf63223e9/chats/g-dce6f5fd-b741-40a6-aa9c-c0e928d9dac5

  • dbd248d7-25c2-4e8f-a23a-99baf63223e9 – team uid
  • g-dce6f5fd-b741-40a6-aa9c-c0e928d9dac5 – chat jid

Send upload as message:

go run examples/send-upload-message/main.go -team <team uid> -token <token> -chat <chat jid> -filepath <path to file>
Simple bot

Echobot: make response to every direct message.

go run examples/echobot/main.go -team <team uid> -token <token>
Delete system alerts

If you not need cleans alerts now, set -dryrun options. Query ruturns you list message delete prepareing

go run examples/delete-messages/main.go -token <token> -team <team uid> -chat <chat jid> -date <2017-12-31 or 2017-01-01 00:10:00>

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InvalidTeamUid = errors.New("invalid team uid")
View Source
var (
	Timeout = errors.New("Timeout")
)

Functions

This section is empty.

Types

type Session

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

func NewSession

func NewSession(server string) (*Session, error)

func (*Session) AddContact added in v0.2.2

func (s *Session) AddContact(teamUid string, phone string) (tdproto.Contact, error)

func (*Session) AddGroupMember added in v0.2.6

func (s *Session) AddGroupMember(teamUid string, group, contact tdproto.JID) (tdproto.GroupMembership, error)

func (*Session) AuthByPasswordGetToken added in v0.2.0

func (s *Session) AuthByPasswordGetToken(username, password string) (tdapi.Auth, error)

func (*Session) AuthBySmsGetToken added in v0.2.0

func (s *Session) AuthBySmsGetToken(phone, code string) (tdapi.Auth, error)

func (*Session) AuthBySmsSendCode added in v0.2.0

func (s *Session) AuthBySmsSendCode(phone string) (tdapi.SmsCode, error)

func (*Session) CloseTask added in v0.7.2

func (s *Session) CloseTask(teamUid, taskUid string) (tdproto.Chat, error)

func (*Session) Contacts added in v0.1.9

func (s *Session) Contacts(teamUid string) ([]tdproto.Contact, error)

func (*Session) CreateGroup added in v0.3.1

func (s *Session) CreateGroup(teamUid string, req tdapi.Group) (tdproto.Chat, error)

func (*Session) CreateTask added in v0.2.6

func (s *Session) CreateTask(teamUid string, req tdapi.Task) (tdproto.Chat, error)

func (*Session) DeleteMessage added in v0.5.0

func (s *Session) DeleteMessage(teamUid string, chat tdproto.JID, msgId string) (tdproto.ChatMessages, error)

func (*Session) DropGroup added in v0.3.1

func (s *Session) DropGroup(teamUid string, group tdproto.JID) error

func (*Session) DropGroupMember added in v0.3.0

func (s *Session) DropGroupMember(teamUid string, group, contact tdproto.JID) error

func (*Session) Features added in v0.1.8

func (s *Session) Features() (*tdproto.Features, error)

func (*Session) GetChats added in v0.4.1

func (s *Session) GetChats(teamUid string, f *tdapi.ChatFilter) ([]tdproto.Chat, error)

func (*Session) GetGroups added in v0.4.0

func (s *Session) GetGroups(teamUid string) ([]tdproto.Chat, error)

func (*Session) GetMessages added in v0.5.0

func (s *Session) GetMessages(teamUid string, chat tdproto.JID, f *tdapi.MessageFilter) ([]tdproto.Message, error)

func (*Session) GroupMembers added in v0.3.0

func (s *Session) GroupMembers(teamUid string, group tdproto.JID) ([]tdproto.GroupMembership, error)

func (*Session) Me

func (s *Session) Me(teamUid string) (tdproto.Contact, error)

func (*Session) Ping

func (s *Session) Ping() error

func (*Session) SendPlaintextMessage added in v0.2.4

func (s *Session) SendPlaintextMessage(teamUid string, chat tdproto.JID, text string) (tdproto.Message, error)

func (*Session) SendUploadMessage added in v0.7.1

func (s *Session) SendUploadMessage(teamUid string, chat tdproto.JID, fname string, file io.ReadCloser) (tdproto.Message, error)

func (*Session) SetCookie added in v0.1.8

func (s *Session) SetCookie(v string)

func (*Session) SetToken

func (s *Session) SetToken(v string)

func (*Session) Ws added in v0.1.4

func (s *Session) Ws(team string) (*WsSession, error)

type WsSession added in v0.1.4

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

func (*WsSession) Close added in v0.2.3

func (w *WsSession) Close() error

func (*WsSession) DeleteMessage added in v0.1.4

func (w *WsSession) DeleteMessage(uid string) error

func (*WsSession) ForeachData added in v0.7.0

func (w *WsSession) ForeachData(eventName string, interfaceHandler func(chan []byte, chan error)) error

func (*WsSession) ForeachMessage added in v0.7.0

func (w *WsSession) ForeachMessage(messageHandler func(chan tdproto.Message, chan error)) error

func (*WsSession) Ping added in v0.1.4

func (w *WsSession) Ping() string

func (*WsSession) SendCallLeave added in v0.6.2

func (w *WsSession) SendCallLeave(jid tdproto.JID)

func (*WsSession) SendCallOffer added in v0.6.2

func (w *WsSession) SendCallOffer(jid tdproto.JID, sdp string)

func (*WsSession) SendEvent added in v0.7.0

func (w *WsSession) SendEvent(event tdproto.Event) error

func (*WsSession) SendPlainMessage added in v0.1.4

func (w *WsSession) SendPlainMessage(to tdproto.JID, text string) string

func (*WsSession) SendRaw added in v0.5.5

func (w *WsSession) SendRaw(b []byte) error

func (*WsSession) Start added in v0.7.0

func (w *WsSession) Start() error

func (*WsSession) StopListeners added in v0.7.0

func (w *WsSession) StopListeners()

func (*WsSession) WaitFor added in v0.1.6

func (w *WsSession) WaitFor(v tdproto.Event) error

func (*WsSession) WaitForConfirm added in v0.1.4

func (w *WsSession) WaitForConfirm() (string, error)

func (*WsSession) WaitForMessage added in v0.1.4

func (w *WsSession) WaitForMessage() (tdproto.Message, bool, error)

Jump to

Keyboard shortcuts

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