Skip to content

Commit

Permalink
bug fixed on message types
Browse files Browse the repository at this point in the history
  • Loading branch information
yagizzcann committed May 24, 2022
1 parent 26306c1 commit 1a8fca5
Showing 1 changed file with 37 additions and 45 deletions.
82 changes: 37 additions & 45 deletions send.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,6 @@ func (api *API) NewMultiBasedTemplate() *MultiBasedTemplate {
return &MultiBasedTemplate{api: api, Type: "template"}
}

func (obj *Media) Send(phoneId, to string) (*MessageResponse, error) {

var rObj interface{}
if obj.IsItAnID {
rObj = obj.ToId()
} else {
rObj = obj.ToLink()
}

r, err := obj.api.send(phoneId, to, obj.Type, rObj)
if err != nil {
return nil, err
}
var res MessageResponse
jsonString, _ := json.Marshal(r)
err = json.Unmarshal(jsonString, &res)
return &res, err
}

func (obj *Text) Send(phoneId, to string) (*MessageResponse, error) {
r, err := obj.api.send(phoneId, to, "text", obj)
if err != nil {
return nil, err
}
var res MessageResponse
jsonString, _ := json.Marshal(r)
json.Unmarshal(jsonString, &res)
return &res, err
}

func (obj *Location) Send(phoneId, to string) (*MessageResponse, error) {
r, err := obj.api.send(phoneId, to, "text", obj)
if err != nil {
return nil, err
}
var res MessageResponse
jsonString, _ := json.Marshal(r)
json.Unmarshal(jsonString, &res)
return &res, err
}

func (api *API) send(phoneId, to, _type string, obj interface{}) (*MessageResponse, error) {
endpoint := fmt.Sprintf("/%s/messages", phoneId)

Expand Down Expand Up @@ -111,6 +70,39 @@ func (api *API) send(phoneId, to, _type string, obj interface{}) (*MessageRespon
return &r, nil
}

func (obj *Media) Send(phoneId, to string) (*MessageResponse, error) {

var rObj interface{}
if obj.IsItAnID {
rObj = obj.ToId()
} else {
rObj = obj.ToLink()
}

r, err := obj.api.send(phoneId, to, obj.Type, rObj)
if err != nil {
return nil, err
}

return r, err
}

func (obj *Text) Send(phoneId, to string) (*MessageResponse, error) {
r, err := obj.api.send(phoneId, to, "text", obj)
if err != nil {
return nil, err
}
return r, err
}

func (obj *Location) Send(phoneId, to string) (*MessageResponse, error) {
r, err := obj.api.send(phoneId, to, "location", obj)
if err != nil {
return nil, err
}
return r, err
}

func (obj *ContactsReq) Send(phoneId, to string) (*MessageResponse, error) {
r, err := obj.api.send(phoneId, to, "contacts", obj)
if err != nil {
Expand All @@ -120,31 +112,31 @@ func (obj *ContactsReq) Send(phoneId, to string) (*MessageResponse, error) {
}

func (obj *Interactive) Send(phoneId, to string) (*MessageResponse, error) {
r, err := obj.api.send(phoneId, to, "contacts", obj)
r, err := obj.api.send(phoneId, to, "interactive", obj)
if err != nil {
return nil, err
}
return r, nil
}

func (obj *InteractiveBtnReq) Send(phoneId, to string) (*MessageResponse, error) {
r, err := obj.api.send(phoneId, to, "contacts", obj)
r, err := obj.api.send(phoneId, to, "interactive", obj)
if err != nil {
return nil, err
}
return r, err
}

func (obj *TextBasedTemplate) Send(phoneId, to string) (*MessageResponse, error) {
r, err := obj.api.send(phoneId, to, "contacts", obj)
r, err := obj.api.send(phoneId, to, "template", obj)
if err != nil {
return nil, err
}
return r, err
}

func (obj *MultiBasedTemplate) Send(phoneId, to string) (*MessageResponse, error) {
r, err := obj.api.send(phoneId, to, "contacts", obj)
r, err := obj.api.send(phoneId, to, "template", obj)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 1a8fca5

Please sign in to comment.