Skip to content
Browse files

add parse_mode to Telegram agent (#1509)

1 parent 93c6a75 commit c15a56989c87169e6d91f3c623373623360207a5 @andrey-yantsen andrey-yantsen committed with May 20, 2016
Showing with 3 additions and 1 deletion.
  1. +3 −1 app/models/agents/telegram_agent.rb
View
4 app/models/agents/telegram_agent.rb
@@ -13,7 +13,7 @@ class TelegramAgent < Agent
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.
- The value of `text` key is sent as a plain text message.
+ 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`.
The value of `photo`, `audio`, `document` and `video` keys should be a url whose contents will be sent to you.
**Setup**
@@ -40,6 +40,7 @@ def default_options
def validate_options
errors.add(:base, 'auth_token is required') unless options['auth_token'].present?
errors.add(:base, 'chat_id is required') unless options['chat_id'].present?
+ 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']
end
def working?
@@ -77,6 +78,7 @@ def receive_event(event)
def send_telegram_message(method, params)
params[:chat_id] = interpolated['chat_id']
+ params[:parse_mode] = interpolated['parse_mode'] if interpolated['parse_mode'].present?
HTTMultiParty.post telegram_bot_uri(method), query: params
end

0 comments on commit c15a569

Please sign in to comment.
Something went wrong with that request. Please try again.