消息反应
Telegram 允许用户使用特定的表情符号对任何消息做出反应,从而触发可爱的 Lottie 动画。
对消息做出反应
reactionEmoji#1b2286b8 emoticon:string = Reaction; reactionCustomEmoji#8935fc73 document_id:long = Reaction; reactionPaid#523da4eb = Reaction;reactionCount#a3d1cb80 flags:# chosen_order:flags.0?int reaction:Reaction count:int = ReactionCount;messagePeerReaction#8c79b63c flags:# big:flags.0?true unread:flags.1?true my:flags.2?true peer_id:Peer date:int reaction:Reaction = MessagePeerReaction;messageReactions#a339f0b flags:# min:flags.0?true can_see_list:flags.2?true reactions_as_tags:flags.3?true results:Vector<ReactionCount> recent_reactions:flags.1?Vector<MessagePeerReaction> top_reactors:flags.4?Vector<MessageReactor> = MessageReactions;message#9815cec8 flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true post:flags.14?true from_scheduled:flags.18?true legacy:flags.19?true edit_hide:flags.21?true pinned:flags.24?true noforwards:flags.26?true invert_media:flags.27?true flags2:# offline:flags2.1?true video_processing_pending:flags2.4?true paid_suggested_post_stars:flags2.8?true paid_suggested_post_ton:flags2.9?true id:int from_id:flags.8?Peer from_boosts_applied:flags.29?int peer_id:Peer saved_peer_id:flags.28?Peer fwd_from:flags.2?MessageFwdHeader via_bot_id:flags.11?long via_business_bot_id:flags2.0?long reply_to:flags.3?MessageReplyHeader date:int message:string media:flags.9?MessageMedia reply_markup:flags.6?ReplyMarkup entities:flags.7?Vector<MessageEntity> views:flags.10?int forwards:flags.10?int replies:flags.23?MessageReplies edit_date:flags.15?int post_author:flags.16?string grouped_id:flags.17?long reactions:flags.20?MessageReactions restriction_reason:flags.22?Vector<RestrictionReason> ttl_period:flags.25?int quick_reply_shortcut_id:flags.30?int effect:flags2.2?long factcheck:flags2.3?FactCheck report_delivery_until_date:flags2.5?int paid_message_stars:flags2.6?long suggested_post:flags2.7?SuggestedPost = Message; messageService#7a800e0a flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true reactions_are_possible:flags.9?true silent:flags.13?true post:flags.14?true legacy:flags.19?true id:int from_id:flags.8?Peer peer_id:Peer saved_peer_id:flags.28?Peer reply_to:flags.3?MessageReplyHeader date:int action:MessageAction reactions:flags.20?MessageReactions ttl_period:flags.25?int = Message;updateMessageReactions#1e297bfa flags:# peer:Peer msg_id:int top_msg_id:flags.0?int saved_peer_id:flags.1?Peer reactions:MessageReactions = Update;messages.messageReactionsList#31bd492d flags:# count:int reactions:Vector<MessagePeerReaction> chats:Vector<Chat> users:Vector<User> next_offset:flags.0?string = messages.MessageReactionsList;---functions---messages.sendReaction#d30d78d4 flags:# big:flags.1?true add_to_recent:flags.2?true peer:InputPeer msg_id:int reaction:flags.0?Vector<Reaction> = Updates; messages.getMessagesReactions#8bba90e6 peer:InputPeer id:Vector<int> = Updates; messages.getMessageReactionsList#461b3f48 flags:# peer:InputPeer id:int reaction:flags.0?Reaction offset:flags.1?string limit:int = messages.MessageReactionsList;messages.getUnreadReactions#bd7f90ac flags:# peer:InputPeer top_msg_id:flags.0?int saved_peer_id:flags.1?InputPeer offset_id:int add_offset:int limit:int max_id:int min_id:int = messages.Messages; messages.readReactions#9ec44f93 flags:# peer:InputPeer top_msg_id:flags.0?int saved_peer_id:flags.1?InputPeer = messages.AffectedHistory;messages.reportReaction#3f64c076 peer:InputPeer id:int reaction_peer:InputPeer = Bool;
用户可以使用`messages.sendReaction`对消息发送一个或多个表情符号;您也可以对已设置相应标志的服务消息reactions_are_possible发送表情符号。
发送表情符号后,`messageReactions`中的 `reactionCount`chosen_order字段将被赋值。该整数值表示表情符号的添加时间:值越大,表示表情符号越新。添加新表情符号时,请使用此值对向量进行排序。表情符号应按升序发送(新表情符号位于向量末尾)。向同一条消息添加多个表情符号时,应移除较旧的表情符号,以确保发送的表情符号总数不超过`reactions_user_max_default`和`reactions_user_max_premium` 的限制。`reactions_uniq_max`配置字段还指示可以添加到消息中的唯一表情符号的最大数量:例如,如果已有 2000 个和 1000 个自定义表情符号,且 `reactions_uniq_max` = 2,则无法添加表情符号,因为这会使唯一表情符号的数量增加到 3 > 2。messages.sendReaction:reaction
messages.sendReaction:reaction
聊天和频道还可以配置自定义的唯一反应数量限制;此信息将在 channelFull 和chatFull中对用户可见。reactions_limitreactions_limit
big可以设置该标志以触发更强烈的反应。
发送reactionEmoji表示使用普通表情符号做出反应,发送reactionCustomEmoji表示使用自定义表情符号做出反应。如果已按此处所述启用,消息作者将在用户对其消息做出反应时
收到updateMessageReactions更新。
messages.getMessagesReactions可用于获取一条或多条消息的完整反应列表。
应用应每 15-30 秒轮询一次可见消息(非用户发送的消息)的反应,但前提是message.reactions已设置此功能。
在群组中,可以使用messages.getMessageReactionsList
获取表情反应列表以及每个表情反应的发送者。
在群组中,可以使用messages.reportReaction举报特定的自定义表情反应,并指定表情反应peer、消息id以及发送该表情反应的用户reaction_peer。
messages.getUnreadReactions用于获取包含未读表情符号的消息。
使用messages.readReactions可以将特定聊天中的所有表情符号标记为已读。
对于已保存的消息,如果设置了messageReactionsreactions_as_tags标志,或者没有反应,则所有当前和未来的反应都应视为消息标签,请参阅此处 » 了解更多信息。
付费反应
reactionPaid#523da4eb = Reaction;---functions---messages.setChatAvailableReactions#864b2581 flags:# peer:InputPeer available_reactions:ChatReactions reactions_limit:flags.0?int paid_enabled:flags.1?Bool = Updates;messages.sendPaidReaction#58bbcb50 flags:# peer:InputPeer msg_id:int count:int random_id:long private:flags.0?PaidReactionPrivacy = Updates;
付费反应(又称星星反应)可以通过调用messages.sendPaidReaction发送到频道帖子:这将把countTelegram 星星转移到频道余额中,并增加类型为reactionPaidcount的星星反应的反应计数器。
注意:messages.sendPaidReactionrandom_id的参数必须由一个 64 位整数组成,其中低 32 位是随机数,高 32 位等于当前 Unix 时间,即:这与API 中所有其他方法的格式不同,其他方法只接受 64 个随机数。 uint64_t random_id = (time() << 32) | ((uint64_t)random_uint32_t())random_id
要启用付费反应,频道管理员必须调用messages.setChatAvailableReactions,将boolTrue传递给它paid_enabled,并将先前配置的反应集传递给它available_reactions(reactions_limit可以省略,因为省略该标志将保留先前配置的值)。
用户可以通过检查channelFullpaid_reactions_available标志的值来确定频道是否支持付费反应。
帖子中可发送的付费表情的最大数量由stars_paid_reaction_amount_max »客户端配置值指定。
付费反应隐私
updatePaidReactionPrivacy#8b725fce private:PaidReactionPrivacy = Update;updateMessageReactions#1e297bfa flags:# peer:Peer msg_id:int top_msg_id:flags.0?int saved_peer_id:flags.1?Peer reactions:MessageReactions = Update;messageReactions#a339f0b flags:# min:flags.0?true can_see_list:flags.2?true reactions_as_tags:flags.3?true results:Vector<ReactionCount> recent_reactions:flags.1?Vector<MessagePeerReaction> top_reactors:flags.4?Vector<MessageReactor> = MessageReactions;messageReactor#4ba3a95a flags:# top:flags.0?true my:flags.1?true anonymous:flags.2?true peer_id:flags.3?Peer count:int = MessageReactor;channels.sendAsPeers#f496b0c6 peers:Vector<SendAsPeer> chats:Vector<Chat> users:Vector<User> = channels.SendAsPeers;---functions---messages.getPaidReactionPrivacy#472455aa = Updates;messages.sendPaidReaction#58bbcb50 flags:# peer:InputPeer msg_id:int count:int random_id:long private:flags.0?PaidReactionPrivacy = Updates;messages.togglePaidReactionPrivacy#435885b5 peer:InputPeer msg_id:int private:PaidReactionPrivacy = Bool;messages.getMessagesReactions#8bba90e6 peer:InputPeer id:Vector<int> = Updates;channels.getSendAs#e785a43f flags:# for_paid_reactions:flags.0?true peer:InputPeer = channels.SendAsPeers;
每个带有星形表情的帖子都有一个排行榜,显示发送者最多的用户,但如果用户更喜欢隐私,可以通过指定相应的PaidReactionPrivacy对象来选择不出现在排行榜上;如果不填充该对象,则会使用存储在服务器上并通过updatePaidReactionPrivacy同步到客户端的默认表情隐私设置(更多信息请参见下文)。
也可以代表我们拥有的频道发送反应;调用channels.getSendAs并加上for_paid_reactions标志,即可获取可用于发送反应的频道列表。
要更改已发送的付费反应的隐私设置,请调用messages.togglePaidReactionPrivacy,并传递消息 ID、频道和所需的隐私设置。
显式指定自定义反应隐私设置,或更改已发送反应的隐私设置,都会更新服务器上存储的默认反应隐私设置:如果新值与旧值不同,则会发出updatePaidReactionPrivacy
更新。
客户端应在启动时调用messages.getPaidReactionPrivacy来获取当前的默认反应隐私设置(因为updatePaidReactionPrivacy更新仅发送给当前在线会话,无法在客户端启动时使用 getDifference 获取)。
要获取付费表情排行榜,请调用messages.getMessagesReactions:返回的updateMessageReactions构造函数将包含一个messageReactortop_reactors向量,其中包含该消息的付费表情排行榜。
对故事做出反应
请点击此处»了解更多关于如何对新闻事件做出反应的信息。
关于反应的通知
reactionNotificationsFromContacts#bac3a61a = ReactionNotificationsFrom; reactionNotificationsFromAll#4b9e22a0 = ReactionNotificationsFrom;reactionsNotifySettings#56e34970 flags:# messages_notify_from:flags.0?ReactionNotificationsFrom stories_notify_from:flags.1?ReactionNotificationsFrom sound:NotificationSound show_previews:Bool = ReactionsNotifySettings;updateNewStoryReaction#1824e40b story_id:int peer:Peer reaction:Reaction = Update; updateMessageReactions#1e297bfa flags:# peer:Peer msg_id:int top_msg_id:flags.0?int saved_peer_id:flags.1?Peer reactions:MessageReactions = Update;---functions---account.setReactionsNotifySettings#316ce548 settings:ReactionsNotifySettings = ReactionsNotifySettings; account.getReactionsNotifySettings#6dd654c = ReactionsNotifySettings;
用户可以选择接收任何用户对其消息和动态发送的回复通知、仅接收联系人发送的回复通知,或者完全禁用这些通知。
可以使用account.setReactionsNotifySettings更改这些反应通知设置,并使用account.getReactionsNotifySettings获取这些设置。
也可以在reactionsNotifySettings字段中为反应设置自定义通知声音 »。sound
如果启用推送通知,则show_previews=false关于消息/故事反应的通知将仅为“/”类型,不包含有关被反应的故事或反应本身的任何信息。REACT_HIDDENREACT_STORY_HIDDEN
动态普通表情符号
reactionEmoji#1b2286b8 emoticon:string = Reaction;availableReaction#c077ec01 flags:# inactive:flags.0?true premium:flags.2?true reaction:string title:string static_icon:Document appear_animation:Document select_animation:Document activate_animation:Document effect_animation:Document around_animation:flags.1?Document center_icon:flags.1?Document = AvailableReaction;messages.availableReactionsNotModified#9f071957 = messages.AvailableReactions; messages.availableReactions#768e3aad hash:int reactions:Vector<AvailableReaction> = messages.AvailableReactions;inputStickerSetEmojiGenericAnimations#04c4d4ce = InputStickerSet;---functions---messages.getAvailableReactions#18dea0ac hash:int = messages.AvailableReactions;
messages.getAvailableReactions可用于获取与普通reactionEmoji互动时要播放的动画列表。返回的availableReaction
构造函数
向量包含多个字段,其中包含 lottie动画贴纸和简单图像,这些贴纸和图像应按照构造函数页面 »中的描述在 UI 中进行适当的定位、显示和播放。
用户还可以使用自定义表情符号进行回复 »,在这种情况下,`appear_animationand`select_animation等于自定义表情符号本身,该表情符号可以通过此处的说明获取 »。
对于自定义表情符号,`and`effect_animation必须等于effect_animation关联的普通表情符号的 `or`:如果与自定义表情符号关联的普通表情符号没有效果动画,则应从`inputStickerSetEmojiGenericAnimations`贴纸集中播放随机动画贴纸,该贴纸集可以通过`messages.getStickerSet`获取,如此处所述»。
组或通道中可用的反应
reactionEmoji#1b2286b8 emoticon:string = Reaction; reactionCustomEmoji#8935fc73 document_id:long = Reaction;chatReactionsNone#eafc32bc = ChatReactions; chatReactionsAll#52928bca flags:# allow_custom:flags.0?true = ChatReactions; chatReactionsSome#661d4037 reactions:Vector<Reaction> = ChatReactions;chatFull#2633421b flags:# can_set_username:flags.7?true has_scheduled:flags.8?true translations_disabled:flags.19?true id:long about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:flags.13?ExportedChatInvite bot_info:flags.3?Vector<BotInfo> pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall ttl_period:flags.14?int groupcall_default_join_as:flags.15?Peer theme_emoticon:flags.16?string requests_pending:flags.17?int recent_requesters:flags.17?Vector<long> available_reactions:flags.18?ChatReactions reactions_limit:flags.20?int = ChatFull; channelFull#e4e0b29d flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true flags2:# can_delete_channel:flags2.0?true antispam:flags2.1?true participants_hidden:flags2.2?true translations_disabled:flags2.3?true stories_pinned_available:flags2.5?true view_forum_as_messages:flags2.6?true restricted_sponsored:flags2.11?true can_view_revenue:flags2.12?true paid_media_allowed:flags2.14?true can_view_stars_revenue:flags2.15?true paid_reactions_available:flags2.16?true stargifts_available:flags2.19?true paid_messages_available:flags2.20?true id:long about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector<BotInfo> migrated_from_chat_id:flags.4?long migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?long location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl_period:flags.24?int pending_suggestions:flags.25?Vector<string> groupcall_default_join_as:flags.26?Peer theme_emoticon:flags.27?string requests_pending:flags.28?int recent_requesters:flags.28?Vector<long> default_send_as:flags.29?Peer available_reactions:flags.30?ChatReactions reactions_limit:flags2.13?int stories:flags2.4?PeerStories wallpaper:flags2.7?WallPaper boosts_applied:flags2.8?int boosts_unrestrict:flags2.9?int emojiset:flags2.10?StickerSet bot_verification:flags2.17?BotVerification stargifts_count:flags2.18?int send_paid_messages_stars:flags2.21?long main_tab:flags2.22?ProfileTab = ChatFull;channelAdminLogEventActionChangeAvailableReactions#be4e0ef8 prev_value:ChatReactions new_value:ChatReactions = ChannelAdminLogEventAction;---functions---messages.setChatAvailableReactions#864b2581 flags:# peer:InputPeer available_reactions:ChatReactions reactions_limit:flags.0?int paid_enabled:flags.1?Bool = Updates;
聊天和频道管理员可以使用`messages.setChatAvailableReactions`来限制聊天或频道中可用的表情符号集合,请参阅此处 »查看可用的配置值列表。用户可以使用`messages.getFullChat`获取 `setChatReactions` 构造函数,
该构造函数将包含在返回的完整信息构造函数的字段中。available_reactions
reactions_limit可以使用 limit 标志来施加唯一反应的自定义限制(即 appConfig.reactions_uniq_max 的可自定义版本);然后,此字段和该方法设置的其他信息将对channelFull和chatFull中的用户可用。
reactions_in_chat_max配置字段指示chatReactionsSome中可以指定的最大反应数。
近期反应
reactionEmoji#1b2286b8 emoticon:string = Reaction; reactionCustomEmoji#8935fc73 document_id:long = Reaction;messages.reactionsNotModified#b06fdbdf = messages.Reactions; messages.reactions#eafdf716 hash:long reactions:Vector<Reaction> = messages.Reactions;updateRecentReactions#6f7863f4 = Update;---functions---messages.getRecentReactions#39461db2 limit:int hash:long = messages.Reactions; messages.clearRecentReactions#9dfeefb4 = Bool;messages.sendReaction#d30d78d4 flags:# big:flags.1?true add_to_recent:flags.2?true peer:InputPeer msg_id:int reaction:flags.0?Vector<Reaction> = Updates;
可以使用messages.getRecentReactions获取最近使用的反应:可以使用messages.clearRecentReactions清除列表。
仅当满足以下条件时,才必须设置add_to_recentmessages.sendReaction 标志:
- 用户使用扩展反应菜单(而不是反应气泡)对消息做出反应。
- 该用户尚未进行付费互动
设置messages.sendReactionadd_to_recent标志将更新最近的反应列表,从而触发其他已登录会话的updateRecentReactions更新。
当收到updateRecentReactions时,客户端应调用messages.getRecentReactions来刷新本地缓存列表。
调用messages.sendReaction的客户端不会收到updateRecentReactions:在这种情况下,客户端可以选择在每次发送反应时手动调用messages.getRecentReactionsadd_to_recent,或者,为了避免额外的调用,它可以手动更新本地列表,hash使用以下算法重新生成:
reactions.prepend(new_reaction)string remove_emoji_selectors(string emoji) {string str;for (i = 0; i < len(emoji); i++) {if (i + 3 <= len(emoji) && emoji[i] == '\xEF' && emoji[i + 1] == '\xB8' && emoji[i + 2] == '\x8F') {// skip \uFE0Fi += 2;} else {str += emoji[i];}}return str;}// Take the char at the specified offset, zero-pad it to a 32-bit integer.uint32 get_char(string str, int offset) {uint8 char = str[offset];return (uint32) char;}vector<uint64> hash_ints = [];foreach (reactions as reaction) {if reaction instanceof reactionEmoji {string emoji = remove_emoji_selectors(reaction.emoticon);// Binary md5 hash, not hexstring hash = md5(emoji);hash_ints.append(0);// First cast to signed int32, then signed int64, then unsigned 64-bit integer.// In other words, cast to a signed int, sign-extend to 64-bit,// then cast back to an unsigned integer.//hash_ints.append((uint64) ((int64) ((int32)((get_char(hash, 0) << 24) + (get_char(hash, 1) << 16) + (get_char(hash, 2) << 8) + get_char(hash, 3)))));} else if reaction instanceof reactionCustomEmoji {hash_ints.append(reaction.document_id >> 32)hash_ints.append(reaction.document_id & 0xFFFFFFFF)}}
然后必须将生成的 64 位整数列表传递给通常的哈希算法。
精选反应
reactionEmoji#1b2286b8 emoticon:string = Reaction; reactionCustomEmoji#8935fc73 document_id:long = Reaction;messages.reactionsNotModified#b06fdbdf = messages.Reactions; messages.reactions#eafdf716 hash:long reactions:Vector<Reaction> = messages.Reactions;---functions---messages.getTopReactions#bb8125ba limit:int hash:long = messages.Reactions;
可以使用messages.getTopReactions获取精选表情符号和自定义表情符号反应的列表。
设置默认反应
reactionEmoji#1b2286b8 emoticon:string = Reaction; reactionCustomEmoji#8935fc73 document_id:long = Reaction;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;updateConfig#a229dd06 = Update;---functions---messages.setDefaultReaction#4f47a016 reaction:Reaction = Bool;help.getConfig#c4f9186b = Config;
messages.setDefaultReaction可用于更改快速反应菜单中使用的默认表情符号反应。此值通过updateConfig
在设备间同步,并且可以使用help.getConfig的field属性获取。reactions_default