This repository has been archived by the owner on Jul 3, 2022. It is now read-only.
forked from Arman92/go-tdlib
/
deepLinkInfo.go
53 lines (44 loc) · 1.68 KB
/
deepLinkInfo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package tdlib
import (
"encoding/json"
"fmt"
)
// DeepLinkInfo Contains information about a tg: deep link
type DeepLinkInfo struct {
tdCommon
Text *FormattedText `json:"text"` // Text to be shown to the user
NeedUpdateApplication bool `json:"need_update_application"` // True, if the user must be asked to update the application
}
// MessageType return the string telegram-type of DeepLinkInfo
func (deepLinkInfo *DeepLinkInfo) MessageType() string {
return "deepLinkInfo"
}
// NewDeepLinkInfo creates a new DeepLinkInfo
//
// @param text Text to be shown to the user
// @param needUpdateApplication True, if the user must be asked to update the application
func NewDeepLinkInfo(text *FormattedText, needUpdateApplication bool) *DeepLinkInfo {
deepLinkInfoTemp := DeepLinkInfo{
tdCommon: tdCommon{Type: "deepLinkInfo"},
Text: text,
NeedUpdateApplication: needUpdateApplication,
}
return &deepLinkInfoTemp
}
// GetDeepLinkInfo Returns information about a tg:// deep link. Use "tg://need_update_for_some_feature" or "tg:some_unsupported_feature" for testing. Returns a 404 error for unknown links. Can be called before authorization
// @param link The link
func (client *Client) GetDeepLinkInfo(link string) (*DeepLinkInfo, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "getDeepLinkInfo",
"link": link,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %v msg: %s", result.Data["code"], result.Data["message"])
}
var deepLinkInfo DeepLinkInfo
err = json.Unmarshal(result.Raw, &deepLinkInfo)
return &deepLinkInfo, err
}