telegram_simple_messenger 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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +8 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +64 -0
- data/Rakefile +12 -0
- data/lib/telegram_simple_messenger/version.rb +5 -0
- data/lib/telegram_simple_messenger.rb +41 -0
- data/sig/telegram_simple_messenger.rbs +4 -0
- metadata +70 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 4ff3d90f49431a1892529477c358267a7bf2f6a419c2f1a8553bd4d50df76aad
|
|
4
|
+
data.tar.gz: ed4412355b3207e23b8730cf3b1f944b131e300ffa6d806570784c432bc448aa
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b9ba940840c78876fa6926b4b3dc30ca70121a85659e4276d00b3bf0d58b526076a1288d71d41b6fc26bbbde0ea4e182a18cf74f03490799f9b2e889d63aa35b
|
|
7
|
+
data.tar.gz: 0d14a9e2bc3e1a2afe80c7b1ddf4d72a467120997027bc21c62409da779f9b0dc765b646844f12efccbd514d80958b0fc95c30fa26e2b1b04cd3af3174bf404f
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Fernando Shayani
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Fernando Shayani
|
|
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,64 @@
|
|
|
1
|
+
# TelegramSimpleMessenger
|
|
2
|
+
|
|
3
|
+
It's a simple gem to send messages through Telegram to a user or a group/channel.
|
|
4
|
+
|
|
5
|
+
## What do you need?
|
|
6
|
+
|
|
7
|
+
To use it, you need and Telegram API KEY (a bot key) and a Chat ID.
|
|
8
|
+
|
|
9
|
+
### API KEY
|
|
10
|
+
The API KEY you can get building a new bot through [@BotFather](https://t.me/botfather). Just send a Telegram message to [@BotFather](https://t.me/botfather) and follows the instructions. An API KEY looks like this: `5490951233:AAFZH99VRQuIOH-qweL1fwATf3kna2eBQSE`.
|
|
11
|
+
|
|
12
|
+
### CHAT ID
|
|
13
|
+
Use another Telegram Bot [@RawDataBot](https://t.me/raw_data_bot) to find your own Chat ID or a group/channel Chat ID.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
Add to your `Gemfile`
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
gem "telegram_simple_messenger", github: "shayani/telegram_simple_messenger"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Then run
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
bundle install
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Configuration
|
|
30
|
+
|
|
31
|
+
Create a initializer file to set the default API KEY and CHAT ID
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
# config/initializers/telegram_simple_messenger.rb
|
|
35
|
+
|
|
36
|
+
TelegramSimpleMessenger.defautl_api_key=MY_API_KEY
|
|
37
|
+
TelegramSimpleMessenger.default_chat_id=MY_CHAT_ID
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
### Sending a message using the default API KEY and CHAT ID
|
|
43
|
+
|
|
44
|
+
Simple call the service:
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
TelegramSimpleMessenger.send_message("Hello world!")
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Overwriting the API KEY and/or CHAT ID
|
|
51
|
+
|
|
52
|
+
You can overwrite the default API KEY and CHAT ID passing them as arguments:
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
TelegramSimpleMessenger.send_message("Hello world!", ANOTHER_API_KEY, ANOTHER_CHAT_ID)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Contributing
|
|
59
|
+
|
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/telegram_simple_messenger.
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "telegram_simple_messenger/version"
|
|
4
|
+
require "httparty"
|
|
5
|
+
|
|
6
|
+
# Send a message to a Telegram chat with a single line of code.
|
|
7
|
+
#
|
|
8
|
+
# You can set a default API key and chat ID:
|
|
9
|
+
# TelegramSimpleMessenger.default_api = "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
|
|
10
|
+
# TelegramSimpleMessenger.default_chat_id = "123456789"
|
|
11
|
+
#
|
|
12
|
+
# Example:
|
|
13
|
+
# TelegramSimpleMessenger.send_message("Hello, world!")
|
|
14
|
+
#
|
|
15
|
+
# You can also pass the API key and chat ID as arguments:
|
|
16
|
+
# TelegramSimpleMessenger.send_message("Hello, world!", "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11", "123456789")
|
|
17
|
+
module TelegramSimpleMessenger
|
|
18
|
+
class Error < StandardError; end
|
|
19
|
+
|
|
20
|
+
class << self
|
|
21
|
+
attr_accessor :default_api_key, :default_chat_id
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
self.default_api_key = nil
|
|
25
|
+
self.default_chat_id = nil
|
|
26
|
+
|
|
27
|
+
def self.send_message(message, api_key = default_api_key, chat_id = default_chat_id)
|
|
28
|
+
raise Error, "No API key provided" unless api_key
|
|
29
|
+
raise Error, "No chat ID provided" unless chat_id
|
|
30
|
+
|
|
31
|
+
response = HTTParty.post("https://api.telegram.org/bot#{api_key}/sendMessage",
|
|
32
|
+
body: {
|
|
33
|
+
chat_id: chat_id,
|
|
34
|
+
text: message
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
raise Error, "Failed to send message: #{response.body}" unless response.success?
|
|
38
|
+
|
|
39
|
+
response
|
|
40
|
+
end
|
|
41
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: telegram_simple_messenger
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Fernando Shayani
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-05-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: httparty
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.18'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.18'
|
|
27
|
+
description: Simple and easy
|
|
28
|
+
email:
|
|
29
|
+
- shayani@gmail.com
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- ".rspec"
|
|
35
|
+
- ".rubocop.yml"
|
|
36
|
+
- CHANGELOG.md
|
|
37
|
+
- LICENSE
|
|
38
|
+
- LICENSE.txt
|
|
39
|
+
- README.md
|
|
40
|
+
- Rakefile
|
|
41
|
+
- lib/telegram_simple_messenger.rb
|
|
42
|
+
- lib/telegram_simple_messenger/version.rb
|
|
43
|
+
- sig/telegram_simple_messenger.rbs
|
|
44
|
+
homepage: https://github.com/shayani/telegram_simple_messenger
|
|
45
|
+
licenses:
|
|
46
|
+
- MIT
|
|
47
|
+
metadata:
|
|
48
|
+
homepage_uri: https://github.com/shayani/telegram_simple_messenger
|
|
49
|
+
source_code_uri: https://github.com/shayani/telegram_simple_messenger
|
|
50
|
+
changelog_uri: https://github.com/shayani/telegram_simple_messenger/CHANGELOG.md
|
|
51
|
+
post_install_message:
|
|
52
|
+
rdoc_options: []
|
|
53
|
+
require_paths:
|
|
54
|
+
- lib
|
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: 3.0.0
|
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
|
+
requirements:
|
|
62
|
+
- - ">="
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: '0'
|
|
65
|
+
requirements: []
|
|
66
|
+
rubygems_version: 3.5.7
|
|
67
|
+
signing_key:
|
|
68
|
+
specification_version: 4
|
|
69
|
+
summary: Send a Telegram message with a single line of code.
|
|
70
|
+
test_files: []
|