telefy 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 45ba5021039d010c2c7497ca017512df821f4c3d14b335fb58ae17bc077274e3
4
+ data.tar.gz: b6144c0ab2818568e48f5d313976b933462706cd753833c6cd58f317d7853ba5
5
+ SHA512:
6
+ metadata.gz: 409853abfe3fa7d2fae1e9f89d90c8aa5f73ddbb35553436ad366b67e3ba473491f1681573e507d732a1ddfa0555ee305ddbc55db59fb0c4bb84f95d94d5cae0
7
+ data.tar.gz: 1db9e7fc42ad644148d5b1e9f2d149cfe1b466a1ee9febd6bf587fbe0aea1f88b493958485177bcdc6fa8ba7382b9c5c05c015611ed3639108124f7e4609951d
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-02-26
4
+
5
+ - Initial release
data/CLAUDE.md ADDED
@@ -0,0 +1,31 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Commands
6
+
7
+ - `bundle exec rake` — run tests + lint (default task)
8
+ - `bundle exec rake test` — tests only (minitest)
9
+ - `bundle exec rake standard` — lint only (StandardRB)
10
+ - `bin/console` — IRB REPL with gem loaded
11
+
12
+ ## Architecture
13
+
14
+ Ruby gem (no runtime deps, stdlib only) for sending Telegram messages via Bot API.
15
+
16
+ **Entry point**: `exe/telefy` → `Telefy::CLI.new(ARGV).run`
17
+
18
+ **Core classes** (all under `lib/telefy/`):
19
+ - `Config` — YAML persistence at `~/.config/telefy/config.yml` (XDG-aware). Lazy load/save of `bot_token` and `chat_id`.
20
+ - `Client` — Telegram Bot API HTTP wrapper using `net/http`. `send_message` and `resolve_chat_id`.
21
+ - `CLI` — Arg parsing. `--setup` for config, otherwise joins args as message text and sends.
22
+
23
+ **Public API**: `Telefy.send_message(text, config:)` in `lib/telefy.rb` for library use.
24
+
25
+ ## Testing
26
+
27
+ Minitest in `test/`. Uses `Dir.mktmpdir` for filesystem isolation and inline `.stub` for HTTP mocking. No fixtures or factories.
28
+
29
+ ## Style
30
+
31
+ StandardRB (`.standard.yml`, targets Ruby 3.2). No custom RuboCop overrides.
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "telefy" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["arzezak@gmail.com"](mailto:"arzezak@gmail.com").
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Ariel Rzezak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Telefy
2
+
3
+ Minimal CLI and Ruby library for sending Telegram messages via the Bot API. Config stored in `~/.config/telefy/config.yml` (XDG). Chat ID auto-resolved on first send.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install telefy
9
+ ```
10
+
11
+ ## Setup
12
+
13
+ 1. Create a bot with [@BotFather](https://t.me/BotFather) and copy the token.
14
+ 2. Run setup:
15
+
16
+ ```bash
17
+ telefy --setup
18
+ ```
19
+
20
+ 3. Send any message to your bot on Telegram.
21
+ 4. Send your first message:
22
+
23
+ ```bash
24
+ telefy "Hello from the terminal"
25
+ ```
26
+
27
+ The chat ID is resolved automatically and saved for future use.
28
+
29
+ ## Usage
30
+
31
+ ```bash
32
+ telefy "Deploy finished" # send a message
33
+ telefy --setup # configure bot token
34
+ telefy --help # show usage
35
+ ```
36
+
37
+ ### As a library
38
+
39
+ ```ruby
40
+ require "telefy"
41
+
42
+ Telefy.send_message("deploy finished")
43
+ ```
44
+
45
+ ## Config
46
+
47
+ Stored at `~/.config/telefy/config.yml` (respects `XDG_CONFIG_HOME`):
48
+
49
+ ```yaml
50
+ bot_token: "123456:ABC-DEF..."
51
+ chat_id: "789012345"
52
+ ```
53
+
54
+ ## Development
55
+
56
+ ```bash
57
+ bin/setup # install deps
58
+ bundle exec rake # tests + linter
59
+ ```
60
+
61
+ ## License
62
+
63
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
64
+
65
+ ## Code of Conduct
66
+
67
+ Everyone interacting in the Telefy project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/arzezak/telefy/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[test standard]
data/exe/telefy ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require "telefy"
6
+
7
+ Telefy::CLI.new(ARGV).run
data/lib/telefy/cli.rb ADDED
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telefy
4
+ class CLI
5
+ USAGE = <<~TEXT
6
+ Usage: telefy [options] [message]
7
+
8
+ telefy --setup Configure bot token
9
+ telefy "message" Send a message (auto-resolves chat ID on first use)
10
+ telefy --help Show this help
11
+ TEXT
12
+
13
+ def initialize(argv, config: Config.new)
14
+ @argv = argv
15
+ @config = config
16
+ end
17
+
18
+ def run
19
+ case @argv.first
20
+ when "--setup" then setup
21
+ when "--help", nil then puts USAGE
22
+ else send_message(@argv.join(" "))
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def setup
29
+ print "Bot token: "
30
+ token = $stdin.gets&.strip
31
+ abort "Aborted." if token.nil? || token.empty?
32
+
33
+ @config.bot_token = token
34
+ puts "Saved to #{@config.path}"
35
+ end
36
+
37
+ def send_message(text)
38
+ client = Client.new(@config.bot_token)
39
+
40
+ unless @config.chat_id
41
+ chat_id = client.resolve_chat_id
42
+ @config.chat_id = chat_id
43
+ puts "Chat ID resolved and saved: #{chat_id}"
44
+ end
45
+
46
+ client.send_message(chat_id: @config.chat_id, text: text)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+ require "uri"
6
+
7
+ module Telefy
8
+ class Client
9
+ def initialize(bot_token)
10
+ raise Error, "Bot token not configured. Run: telefy --setup" unless bot_token
11
+
12
+ @bot_token = bot_token
13
+ end
14
+
15
+ def send_message(chat_id:, text:)
16
+ response = post("sendMessage", chat_id: chat_id, text: text)
17
+ raise Error, "Failed to send message: #{response.body}" unless response.is_a?(Net::HTTPSuccess)
18
+
19
+ JSON.parse(response.body)
20
+ end
21
+
22
+ def resolve_chat_id
23
+ uri = api_uri("getUpdates")
24
+ body = JSON.parse(Net::HTTP.get(uri))
25
+ chat = body.dig("result", 0, "message", "chat", "id")
26
+ raise Error, "No messages found. Message your bot first, then retry." unless chat
27
+
28
+ chat
29
+ end
30
+
31
+ private
32
+
33
+ def post(method, params)
34
+ Net::HTTP.post_form(api_uri(method), params)
35
+ end
36
+
37
+ def api_uri(method)
38
+ URI("https://api.telegram.org/bot#{@bot_token}/#{method}")
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+ require "fileutils"
5
+
6
+ module Telefy
7
+ class Config
8
+ DEFAULT_DIR = File.join(ENV.fetch("XDG_CONFIG_HOME", File.expand_path("~/.config")), "telefy")
9
+ DEFAULT_PATH = File.join(DEFAULT_DIR, "config.yml")
10
+
11
+ attr_reader :path
12
+
13
+ def initialize(path: DEFAULT_PATH)
14
+ @path = path
15
+ end
16
+
17
+ def load
18
+ return {} unless File.exist?(path)
19
+
20
+ YAML.safe_load_file(path, symbolize_names: true) || {}
21
+ end
22
+
23
+ def save(data)
24
+ FileUtils.mkdir_p(File.dirname(path))
25
+ File.write(path, YAML.dump(data.transform_keys(&:to_s)))
26
+ end
27
+
28
+ def bot_token
29
+ load[:bot_token]
30
+ end
31
+
32
+ def chat_id
33
+ load[:chat_id]
34
+ end
35
+
36
+ def bot_token=(value)
37
+ save(load.merge(bot_token: value))
38
+ end
39
+
40
+ def chat_id=(value)
41
+ save(load.merge(chat_id: value))
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telefy
4
+ VERSION = "0.1.0"
5
+ end
data/lib/telefy.rb ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "telefy/version"
4
+ require_relative "telefy/config"
5
+ require_relative "telefy/client"
6
+ require_relative "telefy/cli"
7
+
8
+ module Telefy
9
+ class Error < StandardError; end
10
+
11
+ def self.send_message(text, config: Config.new)
12
+ client = Client.new(config.bot_token)
13
+
14
+ unless config.chat_id
15
+ chat_id = client.resolve_chat_id
16
+ config.chat_id = chat_id
17
+ end
18
+
19
+ client.send_message(chat_id: config.chat_id, text: text)
20
+ end
21
+ end
data/sig/telefy.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Telefy
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: telefy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ariel Rzezak
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Minimal CLI and library for sending Telegram messages via the Bot API
13
+ email:
14
+ - arzezak@gmail.com
15
+ executables:
16
+ - telefy
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - CHANGELOG.md
21
+ - CLAUDE.md
22
+ - CODE_OF_CONDUCT.md
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - exe/telefy
27
+ - lib/telefy.rb
28
+ - lib/telefy/cli.rb
29
+ - lib/telefy/client.rb
30
+ - lib/telefy/config.rb
31
+ - lib/telefy/version.rb
32
+ - sig/telefy.rbs
33
+ homepage: https://github.com/arzezak/telefy
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ homepage_uri: https://github.com/arzezak/telefy
38
+ source_code_uri: https://github.com/arzezak/telefy
39
+ changelog_uri: https://github.com/arzezak/telefy/blob/main/CHANGELOG.md
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 4.0.3
55
+ specification_version: 4
56
+ summary: Send Telegram messages from the command line
57
+ test_files: []