Skip to content

Instantly share code, notes, and snippets.

@marckohlbrugge
Last active January 3, 2024 11:51
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save marckohlbrugge/3d4a6732d6a8c5db9dc2e719d54ac139 to your computer and use it in GitHub Desktop.
Save marckohlbrugge/3d4a6732d6a8c5db9dc2e719d54ac139 to your computer and use it in GitHub Desktop.
Example code for sending notification with Telegram's @PushMoreBot
require "net/https"
class PushMore
WEBHOOK_URL = "https://pushmore.io/webhook/REPLACE_WITH_YOUR_TOKEN"
def initialize(body, format: nil)
@body = body
@format = format
end
def deliver
req = Net::HTTP::Post.new(webhook_url)
req.body = @body
res = Net::HTTP.new(webhook_url.host, webhook_url.port)
res.use_ssl = true
res.verify_mode = OpenSSL::SSL::VERIFY_PEER
res.start { |http| http.request(req) }
end
private
def webhook_url
uri = URI.parse WEBHOOK_URL
uri.query = URI.encode_www_form([["parse_mode", @format.to_s]]) unless @format.nil?
uri
end
end
PushMore.new("hello world").deliver
PushMore.new("<b>hello</b> <i>html</i>", format: :html).deliver
PushMore.new("*hello markdown*", format: :markdown).deliver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment