tdclient

package module
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 20 Imported by: 1

README

Build Status 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
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

func GetIceServer added in v0.5.1

func GetIceServer(host string) (string, error)

func NewPeerConnection added in v0.5.1

func NewPeerConnection(login string, iceServer string) (peerConnection *webrtc.PeerConnection, offer webrtc.SessionDescription, outputTrack *webrtc.Track, err error)

func SendCallLeave added in v0.5.1

func SendCallLeave(c *WsSession, userName string, callJid *tdproto.JID)

func SendCallOffer added in v0.5.1

func SendCallOffer(c *WsSession, userName string, callJid *tdproto.JID, sdp string) (res webrtc.SessionDescription, err error)

Types

type Session

type Session struct {
	Timeout time.Duration
	// 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) 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) SetCookie added in v0.1.8

func (s *Session) SetCookie(v string)

func (*Session) SetToken

func (s *Session) SetToken(v string)

func (*Session) SetVerbose added in v0.1.8

func (s *Session) SetVerbose(v bool)

func (*Session) Ws added in v0.1.4

func (s *Session) Ws(team string, onfail func(error)) (*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) string

func (*WsSession) Ping added in v0.1.4

func (w *WsSession) Ping() string

func (*WsSession) Send added in v0.1.4

func (w *WsSession) Send(event tdproto.Event) string

func (*WsSession) SendPlainMessage added in v0.1.4

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

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)

Directories

Path Synopsis
contacts command
create-task command
delete-messages command
echobot command
groups command
passwordauth command
send-message command
send-message-ws command
serverinfo command
smsauth command

Jump to

Keyboard shortcuts

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