-
Notifications
You must be signed in to change notification settings - Fork 3
Customization
Roman Samoilov edited this page Jul 21, 2023
·
4 revisions
This allows to customize the gem's log output.
TelegramWorkflow.configure do |config|
config.logger = Logger.new("log/telegram.log")
endThis allows to customize the place where all the session data is being saved.
TelegramWorkflow.configure do |config|
config.session_store = TelegramWorkflow::Stores::InMemoryStore
endIt accepts any object that responds to read(key) and write(key, value) methods. Refer to default InMemoryStore class definition.
Use this customization to abstract your action's code from the Telegram API implementation details.
Create a customized client:
class MyClient < TelegramWorkflow::Client
def send_prize_location(user)
# this is an example call
prize = user.find_last_prize
send_venue latitude: prize.latitude,
longitude: prize.longitude,
address: prize.address
title: "Collect the last prize here!",
reply_markup: { keyboard: [[{ text: "Give me a hint" }], [{ text: "Give me anohter hint" }]] }
end
endNow, configure the gem to use the customized client:
TelegramWorkflow.configure do |config|
config.client = MyClient
endThen, in your action:
class FindPrize < TelegramWorkflow::Action
def initial
on_redirect do
client.send_prize_location(current_user)
end
end
endClient can be any class that responds to new(chat_id) method.
Previous: Getting Updates Next: Params