使用 GIF动图

Telegram客户端支持显示GIF动图。

在 Telegram 上,GIF 实际上是没有声音的 MPEG4 (h264) 视频;如果用户尝试上传真正的 GIF 文件,服务器会自动将其转换为 MPEG4 文件。

上传GIF

documentAttributeAnimated#11b58939 = DocumentAttribute;inputMediaUploadedDocument#37c9330 flags:# nosound_video:flags.3?true force_file:flags.4?true spoiler:flags.5?true file:InputFile thumb:flags.2?InputFile mime_type:string attributes:Vector<DocumentAttribute> stickers:flags.0?Vector<InputDocument> video_cover:flags.6?InputPhoto video_timestamp:flags.7?int ttl_seconds:flags.1?int = InputMedia;---functions---messages.sendMedia#ac55d9c1 flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true update_stickersets_order:flags.15?true invert_media:flags.16?true allow_paid_floodskip:flags.19?true peer:InputPeer reply_to:flags.0?InputReplyTo media:InputMedia message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector<MessageEntity> schedule_date:flags.10?int send_as:flags.13?InputPeer quick_reply_shortcut:flags.17?InputQuickReplyShortcut effect:flags.18?long allow_paid_stars:flags.21?long suggested_post:flags.22?SuggestedPost = Updates;

在 Telegram 上,GIF 实际上是没有声音的 MPEG4 视频;如果用户尝试上传真正的 GIF 文件,服务器会自动将其转换为 MPEG4 文件。

要上传 GIF,请按照通常的文件上传程序 »,并指定documentAttributeAnimated。

上传 GIF 会自动将其添加到用户的已保存 GIF 列表中 »。

通过哈希值上传

对于某些类型的文档(例如 GIF),可以使用messages.getDocumentByHash在 Telegram 服务器上搜索文档,而无需从头开始上传。完整步骤
请参见此处 »

已保存的GIF

updateSavedGifs#9375341e = Update;messages.savedGifsNotModified#e8025ca2 = messages.SavedGifs; messages.savedGifs#84a02a0d hash:long gifs:Vector<Document> = messages.SavedGifs;---functions---messages.saveGif#327a30cb id:InputDocument unsave:Bool = Bool; messages.getSavedGifs#5cf09635 hash:long = messages.SavedGifs;

可以使用messages.saveGif将聊天中收到的 GIF 添加到(或从)已保存的 GIF 列表中。

使用上述方法修改已保存的 GIF 列表将向其他当前已登录的会话发出updateSavedGifs更新,这将触发对messages.getSavedGifs的调用,以刷新本地缓存的列表。

首次登录时也应该调用messages.getSavedGifs 。

上传GIF 图像会自动将其添加到已保存的 GIF 列表中。

已保存的 GIF 列表应显示在GIF 选择界面中 »。

对于非高级用户/高级用户,可添加到已保存 GIF 列表中的最大 GIF 数量由appConfig.saved_gifs_limit_default/appConfig.saved_gifs_limit_premium指定。

如果用户在达到非高级版 GIF 添加数量上限后尝试添加更多 GIF,则应弹出高级版订阅提示框。
如果用户在达到非高级版/高级版 GIF 添加数量上限后仍然添加 GIF,服务器将自动删除最早的 GIF,客户端应显示提示信息,告知用户此删除操作。

搜索 GIF

config#cc1a241e flags:# default_p2p_contacts:flags.3?true preload_featured_stickers:flags.4?true revoke_pm_inbox:flags.6?true blocked_mode:flags.8?true force_try_ipv6:flags.14?true date:int expires:int test_mode:Bool this_dc:int dc_options:Vector<DcOption> dc_txt_domain_name:string chat_size_max:int megagroup_size_max:int forwarded_count_max:int online_update_period_ms:int offline_blur_timeout_ms:int offline_idle_timeout_ms:int online_cloud_timeout_ms:int notify_cloud_delay_ms:int notify_default_delay_ms:int push_chat_period_ms:int push_chat_limit:int edit_time_limit:int revoke_time_limit:int revoke_pm_time_limit:int rating_e_decay:int stickers_recent_limit:int channels_read_media_period:int tmp_sessions:flags.0?int call_receive_timeout_ms:int call_ring_timeout_ms:int call_connect_timeout_ms:int call_packet_timeout_ms:int me_url_prefix:string autoupdate_url_prefix:flags.7?string gif_search_username:flags.9?string venue_search_username:flags.10?string img_search_username:flags.11?string static_maps_provider:flags.12?string caption_length_max:int message_length_max:int webfile_dc_id:int suggested_lang_code:flags.2?string lang_pack_version:flags.2?int base_lang_pack_version:flags.2?int reactions_default:flags.15?Reaction autologin_token:flags.16?string = Config;

客户应实现与贴纸搜索界面几乎相同的 GIF 选择/搜索界面,该界面包含一个搜索栏(带有表情符号类别列表),其后(最初)显示已保存的 GIF列表,用户可以选择这些 GIF 并将其发送到当前聊天中。

在搜索栏中输入文本后,应将已保存的 GIF 列表替换为 GIF 搜索结果。该搜索结果必须以内联查询的形式发送到配置中指定的机器人,gif_search_username其中peer`inputPeerEmpty`参数query设置为等于用户输入的内容。
此外,GIF 搜索界面应与贴纸搜索界面几乎完全相同:即使使用了内联机器人查询,GIF 搜索界面也不应使用通常的内联查询界面。

如上所述,GIF 搜索栏还应提供类别列表,以便按表情符号(列表)或其他条件快速筛选结果,请参阅此处»了解更多信息。

选择表情符号类别后,应禁用搜索输入栏,并进行搜索,直接跳至query所选表情符号组的第一个表情符号。