Skip to content

Commit

Permalink
AddContact
Browse files Browse the repository at this point in the history
  • Loading branch information
sdfsdhgjkbmnmxc committed Sep 25, 2020
1 parent 303bd54 commit e5a4fe3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
23 changes: 23 additions & 0 deletions v4.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tdclient

import (
"fmt"

"github.com/pkg/errors"
"github.com/tada-team/tdproto"
"github.com/tada-team/tdproto/tdapi"
Expand Down Expand Up @@ -56,6 +58,27 @@ func (s Session) Contacts(teamUid string) ([]tdproto.Contact, error) {
return resp.Result, nil
}

func (s Session) AddContact(teamUid string, phone string) (tdproto.Contact, error) {
req := map[string]interface{}{
"phone": phone,
}

resp := new(struct {
tdapi.Resp
Result tdproto.Contact `json:"result"`
})

if err := s.doPost(fmt.Sprintf("/api/v4/teams/%s/contacts", teamUid), req, resp); err != nil {
return resp.Result, err
}

if !resp.Ok {
return resp.Result, resp.Error
}

return resp.Result, nil
}

func (s Session) AuthBySmsSendCode(phone string) (tdapi.SmsCode, error) {
req := map[string]interface{}{
"phone": phone,
Expand Down
10 changes: 5 additions & 5 deletions ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,16 @@ func (w *WsSession) WaitFor(name string, v interface{}) error {
}
}

func (w *WsSession) Send(e tdproto.Event) string {
w.outbox <- e
return e.GetConfirmId()
func (w *WsSession) Send(event tdproto.Event) string {
w.outbox <- event
return event.GetConfirmId()
}

func (w *WsSession) outboxLoop() {
for !w.closed {
data := <-w.outbox
event := <-w.outbox

b, err := JSON.Marshal(data)
b, err := JSON.Marshal(event)
if err != nil {
w.fail <- errors.Wrap(err, "json marshal fail")
return
Expand Down

0 comments on commit e5a4fe3

Please sign in to comment.