+func TestOnlyRepliesGetEntities(t *testing.T) {
+ server := newFakeResponses(t)
+ server.reply = func(w http.ResponseWriter, call fakeCall) {
+ writeEvents(w, completedEvent([]any{messageItem("**Done** with `x`.")}, 100, 0, 5))
+ }
+
+ telegram := newFakeBot(t)
+ bot, _ := startTestBot(t, telegram)
+ socket := startTestDaemonWithBot(t, server, bot)
+ terminal := startTestClient(t, socket)
+ terminal.WaitFor(t, "[connected to OneChat]")
+
+ terminal.Type("make **it** so")
+ waitForSent(t, telegram, "[terminal] make **it** so", "Done with x.")
+
+ telegram.Add(botUpdate{
+ UpdateID: 1,
+ Message: ownerMessage(""),
+ })
+
+ waitForSent(t, telegram, textOnly)
+
+ entities := map[string]any{}
+ for _, call := range telegram.Calls() {
+ if call.method == "sendMessage" {
+ entities[call.params["text"].(string)] = call.params["entities"]
+ }
+ }
+
+ require.Equal(t, map[string]any{
+ "[terminal] make **it** so": nil,
+ "Done with x.": []any{
+ map[string]any{
+ "type": "bold",
+ "offset": float64(0),
+ "length": float64(4),
+ },
+ map[string]any{
+ "type": "code",
+ "offset": float64(10),
+ "length": float64(1),
+ },
+ },
+ textOnly: nil,
+ }, entities)
+}
+
+func TestRefusedEntitiesGoAgainAsPlainText(t *testing.T) {
+ telegram := newFakeBot(t)
+ telegram.fail = func(call fakeBotCall) (int, string) {
+ if call.params["entities"] == nil {
+ return 0, ""
+ }
+
+ return http.StatusBadRequest, "Bad Request: can't parse entities of bot" + testBotToken
+ }
+
+ bot, logs := startTestBot(t, telegram)
+ text, entities := markdownEntities("a **secret** word")
+ bot.deliver(t.Context(), botPart{
+ text: text,
+ entities: entities,
+ })
+
+ calls := telegram.Calls()
+ require.Len(t, calls, 2)
+ require.NotNil(t, calls[0].params["entities"])
+ require.Nil(t, calls[1].params["entities"])
+ require.Equal(t, []string{"a secret word"}, telegram.Sent())
+ require.Equal(t, 1, strings.Count(logs.String(), "\n"))
+ require.Contains(t, logs.String(), "entities refused")
+ require.NotContains(t, logs.String(), testBotToken)
+ require.NotContains(t, logs.String(), "secret word")
+}
+