Skip to content

Commit

Permalink
feat: upgrade gleam version to 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bondiano committed Aug 3, 2024
1 parent e483928 commit c4462c3
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: erlef/setup-beam@v1
with:
otp-version: "27.0"
gleam-version: "1.3.1"
gleam-version: "1.4.0"
rebar3-version: "3.23.0"
- name: Install Dependencies
run: gleam deps download
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ fn echo_handler(ctx) {
use <- telega.log_context(ctx, "echo")
case ctx.update {
TextUpdate(text: text, ..) -> reply.with_text(ctx, text)
CommandUpdate(command: command, ..) -> reply.with_text(ctx, command.text)
TextUpdate(text:, ..) -> reply.with_text(ctx, text)
CommandUpdate(command:, ..) -> reply.with_text(ctx, command.text)
_ -> Error("No text message")
}
|> result.map(fn(_) { Nil })
Expand Down
4 changes: 2 additions & 2 deletions examples/00-echo-bot/src/bot.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ fn echo_handler(ctx) {
use <- telega.log_context(ctx, "echo")

case ctx.update {
TextUpdate(text: text, ..) -> reply.with_text(ctx, text)
CommandUpdate(command: command, ..) -> reply.with_text(ctx, command.text)
TextUpdate(text:, ..) -> reply.with_text(ctx, text)
CommandUpdate(command:, ..) -> reply.with_text(ctx, command.text)
_ -> Error("No text message")
}
|> result.map(fn(_) { Nil })
Expand Down
11 changes: 3 additions & 8 deletions examples/01-commands-bot/src/bot.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,12 @@ fn start_command_handler(ctx: NilContext, _) -> Result(Nil, String) {
}

fn build_bot() {
let assert Ok(bot_token) = os.get_env("BOT_TOKEN")
let assert Ok(token) = os.get_env("BOT_TOKEN")
let assert Ok(webhook_path) = os.get_env("WEBHOOK_PATH")
let assert Ok(server_url) = os.get_env("SERVER_URL")
let assert Ok(url) = os.get_env("SERVER_URL")
let assert Ok(secret_token) = os.get_env("BOT_SECRET_TOKEN")

telega.new(
token: bot_token,
url: server_url,
webhook_path: webhook_path,
secret_token: Some(secret_token),
)
telega.new(token:, url:, webhook_path:, secret_token: Some(secret_token))
|> telega.handle_command("dice", dice_command_handler)
|> telega.handle_command("start", start_command_handler)
|> telega.init_nil_session
Expand Down
11 changes: 3 additions & 8 deletions examples/02-session-bot/src/bot.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,12 @@ fn start_command_handler(ctx, _) -> Result(NameBotSession, String) {
}

fn build_bot() {
let assert Ok(bot_token) = os.get_env("BOT_TOKEN")
let assert Ok(token) = os.get_env("BOT_TOKEN")
let assert Ok(webhook_path) = os.get_env("WEBHOOK_PATH")
let assert Ok(server_url) = os.get_env("SERVER_URL")
let assert Ok(url) = os.get_env("SERVER_URL")
let assert Ok(secret_token) = os.get_env("BOT_SECRET_TOKEN")

telega.new(
token: bot_token,
url: server_url,
webhook_path: webhook_path,
secret_token: Some(secret_token),
)
telega.new(token:, url:, webhook_path:, secret_token: Some(secret_token))
|> telega.handle_command("start", start_command_handler)
|> telega.handle_command("set_name", set_name_command_handler)
|> telega.handle_command("get_name", get_name_command_handler)
Expand Down
11 changes: 3 additions & 8 deletions examples/03-conversation-bot/src/bot.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,12 @@ fn start_command_handler(ctx, _) -> Result(NameBotSession, String) {
}

fn build_bot() {
let assert Ok(bot_token) = os.get_env("BOT_TOKEN")
let assert Ok(token) = os.get_env("BOT_TOKEN")
let assert Ok(webhook_path) = os.get_env("WEBHOOK_PATH")
let assert Ok(server_url) = os.get_env("SERVER_URL")
let assert Ok(url) = os.get_env("SERVER_URL")
let assert Ok(secret_token) = os.get_env("BOT_SECRET_TOKEN")

telega.new(
token: bot_token,
url: server_url,
webhook_path: webhook_path,
secret_token: Some(secret_token),
)
telega.new(token:, url:, webhook_path:, secret_token: Some(secret_token))
|> telega.handle_command("start", start_command_handler)
|> telega.handle_command("set_name", set_name_command_handler)
|> telega.handle_command("get_name", get_name_command_handler)
Expand Down
11 changes: 3 additions & 8 deletions examples/04-keyboard-bot/src/bot.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,12 @@ fn start_command_handler(
}

fn build_bot() {
let assert Ok(bot_token) = os.get_env("BOT_TOKEN")
let assert Ok(token) = os.get_env("BOT_TOKEN")
let assert Ok(webhook_path) = os.get_env("WEBHOOK_PATH")
let assert Ok(server_url) = os.get_env("SERVER_URL")
let assert Ok(url) = os.get_env("SERVER_URL")
let assert Ok(secret_token) = os.get_env("BOT_SECRET_TOKEN")

telega.new(
token: bot_token,
url: server_url,
webhook_path: webhook_path,
secret_token: Some(secret_token),
)
telega.new(token:, url:, webhook_path:, secret_token: Some(secret_token))
|> telega.handle_command("start", start_command_handler)
|> telega.handle_command("lang", change_languages_keyboard)
|> telega.handle_command("lang_inline", handle_inline_change_language)
Expand Down
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ links = [
{ title = "Examples", href = "https://github.com/bondiano/telega/tree/master/examples"}
]

gleam = "~> 1.3.0"
gleam = ">= 0.32.0"
target = "erlang"

[dependencies]
Expand Down
17 changes: 6 additions & 11 deletions src/telega.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ pub fn new(
) -> TelegaBuilder(session) {
TelegaBuilder(
handlers: [],
config: config.new(
token: token,
url: server_url,
webhook_path: webhook_path,
secret_token: secret_token,
),
config: config.new(token:, webhook_path:, secret_token:, url: server_url),
registry_subject: None,
session_settings: None,
)
Expand Down Expand Up @@ -258,11 +253,11 @@ pub fn init(builder: TelegaBuilder(session)) -> Result(Telega(session), String)
let registry_actor =
supervisor.supervisor(fn(_) {
bot.start_registry(
bot_info:,
session_settings:,
config: builder.config,
handlers: builder.handlers,
session_settings: session_settings,
root_subject: telega_subject,
bot_info: bot_info,
)
})

Expand All @@ -280,11 +275,11 @@ pub fn init(builder: TelegaBuilder(session)) -> Result(Telega(session), String)
)

Ok(Telega(
bot_info:,
registry_subject:,
session_settings:,
config: builder.config,
handlers: builder.handlers,
bot_info: bot_info,
registry_subject: registry_subject,
session_settings: session_settings,
))
}

Expand Down
8 changes: 4 additions & 4 deletions src/telega/api.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ pub fn send_dice(
let body_json = model.encode_send_dice_parameters(parameters)

new_post_request(
config: config,
config:,
path: "sendDice",
query: None,
body: json.to_string(body_json),
Expand Down Expand Up @@ -272,7 +272,7 @@ pub fn answer_callback_query(
let body_json = model.encode_answer_callback_query_parameters(parameters)

new_post_request(
config: config,
config:,
path: "answerCallbackQuery",
query: None,
body: json.to_string(body_json),
Expand All @@ -292,7 +292,7 @@ pub fn edit_message_text(
let body_json = model.encode_edit_message_text_parameters(parameters)

new_post_request(
config: config,
config:,
path: "editMessageText",
query: None,
body: json.to_string(body_json),
Expand All @@ -312,7 +312,7 @@ pub fn forward_message(
let body_json = model.encode_forward_message_parameters(parameters)

new_post_request(
config: config,
config:,
path: "forwardMessage",
query: None,
body: json.to_string(body_json),
Expand Down
16 changes: 8 additions & 8 deletions src/telega/bot.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ pub fn start_registry(
|> process.selecting(registry_subject, function.identity)

Registry(
config:,
handlers:,
bot_info:,
session_settings:,
registry_subject:,
bot_instances_subject:,
bots: dict.new(),
config: config,
session_settings: session_settings,
handlers: handlers,
registry_subject: registry_subject,
bot_instances_subject: bot_instances_subject,
bot_info: bot_info,
)
|> actor.Ready(selector)
},
Expand All @@ -186,7 +186,7 @@ pub fn wait_handler(

fn new_context(bot: BotInstanse(session), update: Update) -> Context(session) {
Context(
update: update,
update:,
key: bot.key,
config: bot.config,
session: bot.session,
Expand Down Expand Up @@ -243,8 +243,8 @@ fn start_bot_instanse(
case get_session(registry.session_settings, update) {
Ok(session) ->
BotInstanse(
session:,
key: session_key,
session: session,
bot_info: registry.bot_info,
config: registry.config,
handlers: registry.handlers,
Expand Down
6 changes: 3 additions & 3 deletions src/telega/internal/config.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ pub fn new(
})

Config(
server_url: server_url,
webhook_path: webhook_path,
secret_token: secret_token,
server_url:,
webhook_path:,
secret_token:,
api: TelegramApiConfig(
token,
max_retry_attempts: default_retry_count,
Expand Down
24 changes: 7 additions & 17 deletions src/telega/keyboard.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn selected(keyboard: Keyboard) -> Keyboard {
/// Create a new keyboard button
pub fn button(text: String) -> KeyboardButton {
KeyboardButton(
text: text,
text:,
request_users: None,
request_chat: None,
request_contact: None,
Expand Down Expand Up @@ -118,7 +118,7 @@ pub fn inline_button(
callback_data callback_data: KeyboardCallback(data),
) -> InlineKeyboardButton {
InlineKeyboardButton(
text: text,
text:,
callback_data: Some(callback_data.payload),
url: None,
login_url: None,
Expand Down Expand Up @@ -172,12 +172,7 @@ pub fn new_callback_data(
serilize serilize: fn(data) -> String,
deserialize deserialize: fn(String) -> data,
) {
KeyboardCallbackData(
id: id,
serilize: serilize,
deserialize: deserialize,
delimiter: ":",
)
KeyboardCallbackData(id:, serilize:, deserialize:, delimiter: ":")
}

/// Change the delimiter for the callback data, usefull if you need to use `:` in the id
Expand All @@ -196,12 +191,7 @@ pub fn pack_callback(
let payload =
callback_data.id <> callback_data.delimiter <> callback_data.serilize(data)

KeyboardCallback(
id: callback_data.id,
payload: payload,
data: data,
callback_data: callback_data,
)
KeyboardCallback(data:, payload:, callback_data:, id: callback_data.id)
}

/// Unpack payload into a callback
Expand All @@ -215,9 +205,9 @@ pub fn unpack_callback(
))

Ok(KeyboardCallback(
id: id,
payload: payload,
id:,
payload:,
callback_data:,
data: callback_data.deserialize(data),
callback_data: callback_data,
))
}
6 changes: 3 additions & 3 deletions src/telega/update.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn try_to_decode_message_or_command(
raw: message,
))
False ->
Ok(TextUpdate(chat_id: message.chat.id, text: text, raw: message))
Ok(TextUpdate(text:, chat_id: message.chat.id, raw: message))
}
}
None -> on_none()
Expand Down Expand Up @@ -106,12 +106,12 @@ fn extract_command(text: String) -> Command {
case string.split(text, " ") {
[command, ..payload] ->
Command(
text: text,
text:,
command: string.drop_left(command, 1),
payload: payload
|> string.join(" ")
|> Some,
)
[] -> Command(text: text, command: "", payload: None)
[] -> Command(text:, command: "", payload: None)
}
}

0 comments on commit c4462c3

Please sign in to comment.