aboutsummaryrefslogtreecommitdiff
path: root/telegram
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2022-06-29 16:56:27 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2022-06-29 16:56:27 +0300
commit38ffdb9e4791652b09d59643c8e0b200c2566e1c (patch)
treefd64275dd2144b350b49e0fef9a998008bb204db /telegram
parent76ac66236612315860538a73334e6c7d10c7c4b4 (diff)
Retrieve Bio / Description for vCard desc / note
Diffstat (limited to 'telegram')
-rw-r--r--telegram/utils.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/telegram/utils.go b/telegram/utils.go
index a4f3899..4c365a3 100644
--- a/telegram/utils.go
+++ b/telegram/utils.go
@@ -1023,6 +1023,47 @@ func (c *Client) OpenPhotoFile(photoFile *client.File, priority int32) (*os.File
return nil, path, err
}
+// GetChatDescription obtains bio or description according to the chat type
+func (c *Client) GetChatDescription(chat *client.Chat) string {
+ chatType := chat.Type.ChatTypeType()
+ if chatType == client.TypeChatTypePrivate {
+ privateType, _ := chat.Type.(*client.ChatTypePrivate)
+ fullInfo, err := c.client.GetUserFullInfo(&client.GetUserFullInfoRequest{
+ UserId: privateType.UserId,
+ })
+ if err == nil {
+ if fullInfo.Bio != "" {
+ return fullInfo.Bio
+ } else if fullInfo.Description != "" {
+ return fullInfo.Description
+ }
+ } else {
+ log.Warnf("Coudln't retrieve private chat info: %v", err.Error())
+ }
+ } else if chatType == client.TypeChatTypeBasicGroup {
+ basicGroupType, _ := chat.Type.(*client.ChatTypeBasicGroup)
+ fullInfo, err := c.client.GetBasicGroupFullInfo(&client.GetBasicGroupFullInfoRequest{
+ BasicGroupId: basicGroupType.BasicGroupId,
+ })
+ if err == nil {
+ return fullInfo.Description
+ } else {
+ log.Warnf("Coudln't retrieve basic group info: %v", err.Error())
+ }
+ } else if chatType == client.TypeChatTypeSupergroup {
+ supergroupType, _ := chat.Type.(*client.ChatTypeSupergroup)
+ fullInfo, err := c.client.GetSupergroupFullInfo(&client.GetSupergroupFullInfoRequest{
+ SupergroupId: supergroupType.SupergroupId,
+ })
+ if err == nil {
+ return fullInfo.Description
+ } else {
+ log.Warnf("Coudln't retrieve supergroup info: %v", err.Error())
+ }
+ }
+ return ""
+}
+
// subscribe to a Telegram ID
func (c *Client) subscribeToID(id int64, chat *client.Chat) {
var args []args.V