Skip to content

Commit 69daf12

Browse files
author
Andrey Oskin
committed
Major refactoring and full documentation
1 parent cdf0089 commit 69daf12

18 files changed

+2172
-95
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ jobs:
1212
strategy:
1313
matrix:
1414
version:
15-
- '1.0'
1615
- '1.3'
17-
- '1.5'
16+
- 'nightly'
1817
os:
1918
- ubuntu-latest
2019
- macOS-latest
@@ -43,6 +42,7 @@ jobs:
4342
- run: julia --project=docs -e '
4443
using Pkg;
4544
Pkg.develop(PackageSpec(; path=pwd()));
45+
Pkg.add(PackageSpec(url="https://github.com/Arkoniak/Documenter.jl", rev="repo_url"));
4646
Pkg.instantiate();'
4747
- run: julia --project=docs docs/make.jl
4848
env:

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Telegram"
22
uuid = "1da6f4ae-116c-4c38-8ee9-19974ff3601d"
33
authors = ["Andrey Oskin"]
4-
version = "0.1.0"
4+
version = "0.2.0"
55

66
[deps]
77
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"

README.md

+75-15
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,104 @@
55
[![Build Status](https://travis-ci.com/Arkoniak/Telegram.jl.svg?branch=master)](https://travis-ci.com/Arkoniak/Telegram.jl)
66
[![Coverage](https://codecov.io/gh/Arkoniak/Telegram.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/Arkoniak/Telegram.jl)
77

8-
Telegram api wrapper
8+
Simple [Telegram Messaging](https://telegram.org/) SDK with logging and bot facilities. Package was built with first-class support of telegram as instant message backend for various notification and reporing systems. So, simpliest way to use this package is by doing something like this
9+
10+
```julia
11+
using Telegram, Telegram.API
12+
tg = TelegramClient("YOUR TOKEN", chat_id = "YOUR CHAT_ID")
13+
14+
# Some lengthy calculation
15+
# ...
16+
17+
sendMessage(text = "Calculation complete, result is $result")
18+
```
19+
20+
Please refer to [documentation](https://Arkoniak.github.io/Telegram.jl/dev) to learn how to properly setup telegram credentials and use package in general.
921

1022
# Installation
1123

12-
Currently package is not registered, so it should be installed from source
24+
Package is registered so you can install it in a usual way
1325

1426
```julia
1527
julia> using Pkg
16-
julia> Pkg.add("https://github.com/Arkoniak/Telegram.jl.git")
28+
julia> Pkg.add("Telegram")
1729
```
1830

1931
# Usage
2032

33+
## Telegram API
34+
2135
Usage is straightforward, [Telegram API methods](https://core.telegram.org/bots/api#available-methods) are in one to one correspondence with this Julia wrapper. You need to create connection and then simply call necessary methods
2236

2337
```julia
38+
julia> using Telegram, Telegram.API
2439
julia> token = "HERE SHOULD BE YOUR TOKEN"
25-
julia> client = TelegramClient(token)
40+
julia> TelegramClient(token)
2641

27-
julia> getMe(client)
28-
JSON3.Object{Base.CodeUnits{UInt8,String},Array{UInt64,1}} with 2 entries:
29-
:ok => true
30-
:result => {
42+
julia> getMe()
43+
JSON3.Object{Array{UInt8,1},SubArray{UInt64,1,Array{UInt64,1},Tuple{UnitRange{Int64}},true}} with 7 entries:
44+
:id => 123456789
45+
:is_bot => true
46+
:first_name => "Awesome Bot"
47+
:username => "AwesomeBot"
48+
:can_join_groups => true
49+
:can_read_all_group_messages => false
50+
:supports_inline_queries => false
3151
```
3252

33-
You can necessary arguments in methods, but some subset can be set in `client` itself
53+
Mainly you need to set arguments, but `chat_id` can be set directly in `TelegramClient`
3454

3555
```julia
3656
julia> token = "HERE SHOULD BE YOUR TOKEN"
37-
julia> client = TelegramClient(token; chat_id = "HERE SHOULD BE CHAT_ID")
57+
julia> TelegramClient(token; chat_id = "HERE SHOULD BE CHAT_ID")
3858

39-
julia> sendMessage(client, text = "Hello, world!")
59+
julia> sendMessage(text = "Hello, world!")
4060
```
41-
or equivalently
61+
62+
You can send files and other `io` objects
4263

4364
```julia
44-
julia> token = "HERE SHOULD BE YOUR TOKEN"
45-
julia> client = TelegramClient(token)
65+
julia> sendPhoto(photo = open("picture.jpg", "r"))
66+
julia> io = IOBuffer()
67+
julia> print(io, "Hello world!")
68+
julia> sendDocument(document = "hello.txt" => io)
69+
```
70+
71+
## Logging
72+
73+
You can use [Telegram.jl](https://github.com/Arkoniak/Telegram.jl) together with [LoggingExtras.jl](https://github.com/oxinabox/LoggingExtras.jl) to create powerful logging with insta messaging in case of critical situations
74+
75+
```julia
76+
using Telegram
77+
using Logging, LoggingExtras
78+
79+
# considering that token and chat_id variables are set as corresponding
80+
# environment variables
81+
tg = TelegramClient(ENV["TG_TOKEN"], chat_id = ENV["TG_CHAT_ID"])
82+
tg_logger = TelegramLogger(tg; async = false)
83+
demux_logger = TeeLogger(
84+
MinLevelLogger(tg_logger, Logging.Error),
85+
ConsoleLogger()
86+
)
87+
global_logger(demux_logger)
88+
89+
@warn "It is bad" # goes to console
90+
@info "normal stuff" # goes to console
91+
@error "THE WORSE THING" # goes to console and telegram
92+
@debug "it is chill" # goes to console
93+
```
94+
95+
## Bots
96+
97+
You can create bot very easy with the `run_bot` command. Here is for example Echo bot
98+
```julia
99+
using Telegram, Telegram.API
100+
101+
token = ENV["TG_TOKEN"]
102+
tg = TelegramClient(token)
46103

47-
julia> sendMessage(client; text = "Hello, world!", chat_id = "HERE SHOULD BE CHAT_ID")
104+
# Echo bot
105+
run_bot() do msg
106+
sendMessage(text = msg.message.text, chat_id = msg.message.chat.id)
107+
end
48108
```

docs/make.jl

+4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ makedocs(;
99
format=Documenter.HTML(;
1010
prettyurls=get(ENV, "CI", "false") == "true",
1111
canonical="https://Arkoniak.github.io/Telegram.jl",
12+
siteurl="https://github.com/Arkoniak/Telegram.jl",
1213
assets=String[],
1314
),
1415
pages=[
1516
"Home" => "index.md",
17+
"API Reference" => "reference.md",
18+
"Usage" => "usage.md",
19+
"Developer guide" => "developers.md"
1620
],
1721
)
1822

docs/src/developers.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Developer guide
2+
3+
Please note, that api functions themselves are not written manually, but automatically generated by parsing [https://core.telegram.org/bots/api](https://core.telegram.org/bots/api) site. So, if you find any inconsistences, missing docstrings or missing methods please do not make changes to `src/telegram_api.jl` or `reference.md`. Instead you should change scraping script accordingly. This script can be found in `extras` directory and in order to build new docs and methods you should do the following
4+
5+
```sh
6+
sh> cd extras
7+
sh> julia
8+
julia> ]
9+
pkg> activate .
10+
(extras)> instantiate
11+
```
12+
13+
After that you can exit julia session and run
14+
```sh
15+
sh> julia make.jl
16+
```
17+
command. It will create two files:
18+
* `src/telegram_api.jl` which contains all methods names and corresponding docstrings
19+
* `docs/src/reference.md` which contains complete [API Reference](@ref) page.
20+

docs/src/index.md

+21-47
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,30 @@ CurrentModule = Telegram
33
```
44

55
# Telegram
6+
Simple [Telegram Messaging](https://telegram.org/) SDK with logging and bot facilities. Package was built with first-class support of telegram as instant message backend for various notification and reporing systems. So, simpliest way to use this package is by doing something like this
67

7-
Supported methods
8-
- [X] getMe
9-
- [X] sendMessage
10-
- [ ] forwardMessage
11-
- [ ] sendPhoto
12-
- [ ] sendAudio
13-
- [ ] sendDocument
14-
- [ ] sendVideo
15-
- [ ] sendAnimation
16-
- [ ] sendVoice
17-
- [ ] sendVideoNote
18-
- [ ] sendMediaGroup
19-
- [ ] sendLocation
20-
- [ ] editMessageLiveLocation
21-
- [ ] stopMessageLiveLocation
22-
- [ ] sendVenue
23-
- [ ] sendContact
24-
- [ ] sendPoll
25-
- [ ] sendDice
26-
- [ ] sendChatAction
27-
- [ ] getUserProfilePhotos
28-
- [ ] getFile
29-
- [X] kickChatMember
30-
- [X] unbanChatMember
31-
- [X] restrictChatMember
32-
- [X] promoteChatMember
33-
- [X] setChatAdministratorCustomTitle
34-
- [X] setChatPermissions
35-
- [X] exportChatInviteLink
36-
- [ ] setChatPhoto
37-
- [X] deleteChatPhoto
38-
- [X] setChatTitle
39-
- [X] setChatDescription
40-
- [X] pinChatMessage
41-
- [X] unpinChatMessage
42-
- [X] leaveChat
43-
- [X] getChat
44-
- [X] getChatAdministrators
45-
- [X] getChatMembersCount
46-
- [X] getChatMember
47-
- [X] setChatStickerSet
48-
- [X] deleteChatStickerSet
49-
- [ ] answerCallbackQuery
50-
- [ ] setMyCommands
51-
- [ ] getMyCommands
52-
53-
```@index
8+
```julia
9+
using Telegram, Telegram.API
10+
tg = TelegramClient("YOUR TOKEN", chat_id = "YOUR CHAT_ID")
11+
12+
# Some lengthy calculation
13+
# ...
14+
15+
sendMessage(text = "Calculation complete, result is $result")
5416
```
5517

18+
## Installation
19+
Package is registered so you can install it in a usual way
20+
21+
```julia
22+
julia> using Pkg
23+
julia> Pkg.add("Telegram")
24+
```
25+
26+
## General methods
27+
28+
In addition to [API Reference](@ref) methods, there is a number of methods which add some julian functionality like bots and logging facilities.
29+
5630
```@autodocs
5731
Modules = [Telegram]
5832
```

0 commit comments

Comments
 (0)