Commit 5765b3d
authored
feat(telegram): route bot commands to slash-command handlers (chat@4.31 9c936f8) (#154)
* feat(telegram): route bot commands to slash-command handlers (chat@4.31 9c936f8)
Port upstream Telegram slash-command routing. process_update now gates a
new handle_slash_command_update before handle_incoming_message_update,
but only for update.message (not edited messages or channel posts), so a
leading /command routes to the core process_slash_command surface
instead of process_message.
parse_slash_command requires a bot_command entity at offset 0 (an
offset-7 command stays a regular message), matches @bot targeting
case-insensitively against user_name (/ping@otherbot is ignored), reads
the caption/caption_entities path when text is absent (has_text = text
is not None, so empty-string text still takes the text branch), and
splits the command from its trailing text on UTF-16-LE code-unit offsets
via a new _slice_utf16 helper rather than naive str slicing.
The event mirrors the Discord adapter: SlashCommandEvent(channel=None)
with the resolved thread id attached as channel_id for Chat to re-wrap.
Adds 7 regression tests (routes command, routes caption, ignores
otherbot, only-leading-entity, empty-string-text branch, UTF-16 split,
naive-slice divergence guard).
* test(telegram): de-phantom UTF-16 split test, add slash-routing coverage
Make test_trailing_text_split_uses_utf16_offsets genuinely exercise the
UTF-16 code-unit split. The prior input ("/p😀g hello") converged: a
separating space meant naive code-point slicing and UTF-16-LE offset
slicing both yielded "hello" after lstrip, so the test passed against a
naive text[entity_length:] implementation. The new input ("/p😀ghello")
abuts the trailing text with no separator, so the naive slice over-
advances and drops the leading "h" ("ello"), while the UTF-16-aware
split keeps it ("hello") — verified to FAIL against a reverted naive
slice.
Add targeted regression coverage, each pinned to a distinct mutation:
- @bot targeting is case-insensitive (/ping@MyBot routes when user_name
is "mybot"); fails under a case-sensitive comparison.
- slash gating is scoped to update.message only: edited_message and
channel_post carrying a leading bot_command entity route to
process_message, never the slash handler; fails if the gate widens to
message_update.
- empty-command guard: /@Mybot and a bare / yield no slash command and
route to process_message (matches upstream's if (!commandName)); fails
if the guard is removed.1 parent f801985 commit 5765b3d
2 files changed
Lines changed: 426 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| |||
1049 | 1050 | | |
1050 | 1051 | | |
1051 | 1052 | | |
1052 | | - | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
1053 | 1062 | | |
1054 | 1063 | | |
1055 | 1064 | | |
| |||
1079 | 1088 | | |
1080 | 1089 | | |
1081 | 1090 | | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
1082 | 1188 | | |
1083 | 1189 | | |
1084 | 1190 | | |
| |||
2493 | 2599 | | |
2494 | 2600 | | |
2495 | 2601 | | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
2496 | 2614 | | |
2497 | 2615 | | |
2498 | 2616 | | |
| |||
0 commit comments