add parse_mode to Telegram agent (#1509)

Andrey Yantsen лет %!s(int64=8): %!d(string=назад)
Родитель
Сommit
c15a56989c
1 измененных файлов с 3 добавлено и 1 удалено
  1. 3 1
      app/models/agents/telegram_agent.rb

+ 3 - 1
app/models/agents/telegram_agent.rb

@@ -13,7 +13,7 @@ module Agents
13 13
 
14 14
       It is assumed that events have either a `text`, `photo`, `audio`, `document` or `video` key. You can use the EventFormattingAgent if your event does not provide these keys.
15 15
 
16
-      The value of `text` key is sent as a plain text message.
16
+      The value of `text` key is sent as a plain text message. You can also tell Telegram how to parse the message with `parse_mode`, set to either `html` or `markdown`.
17 17
       The value of `photo`, `audio`, `document` and `video` keys should be a url whose contents will be sent to you.
18 18
 
19 19
       **Setup**
@@ -40,6 +40,7 @@ module Agents
40 40
     def validate_options
41 41
       errors.add(:base, 'auth_token is required') unless options['auth_token'].present?
42 42
       errors.add(:base, 'chat_id is required') unless options['chat_id'].present?
43
+      errors.add(:base, 'parse_mode has invalid value: should be html or markdown') if interpolated['parse_mode'].present? and !['html', 'markdown'].include? interpolated['parse_mode']
43 44
     end
44 45
 
45 46
     def working?
@@ -77,6 +78,7 @@ module Agents
77 78
 
78 79
     def send_telegram_message(method, params)
79 80
       params[:chat_id] = interpolated['chat_id']
81
+      params[:parse_mode] = interpolated['parse_mode'] if interpolated['parse_mode'].present?
80 82
       HTTMultiParty.post telegram_bot_uri(method), query: params
81 83
     end
82 84