• This repository has been archived on 05/Apr/2022
  • Stars
    star
    1
  • Language
    Crystal
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Broadcasting for Tele 📢

Tele::Broadcast Build Status Docs GitHub release

A broadcasting module for Tele.cr.

Installation

Add this to your application's shard.yml:

dependencies:
  tele-broadcast:
    github: vladfaust/tele-broadcast.cr
    version: ~> 0.1.3

Usage

Read some docs when you need.

Tele::Broadcast is agnostic of ORM structure, you just pass a list of Tele::Requests and an list of recipients chat IDs and run the Woker. You can either create a custom CLI for broadcasting from the local machine or develop a web-interface.

Client

The client allows to schedule broadcasts:

require "tele/requests/send_message"
require "tele-broadcast/client"
require "tele-broadcast/repositories/redis"

logger = Logger.new(STDOUT).tap(&.level = Logger::DEBUG)
repo = Tele::Broadcast::Repositories::Redis.new(Redis.new, logger, "example_bot:broadcast:") # Don't forget to add a colon in the end of namespace

client = Tele::Broadcast::Client.new(repo, logger)

request = Tele::Requests::SendMessage.new(chat_id: 0, text: "Hello from Tele::Broadcast!")
recipients = [116543174, 155633478] of Int32 # A list of Telegram IDs

client.broadcast(requests, recipients)

# => INFO -- : Added payload #1 to the broadcasting queue

Check out examples/client.cr and try it yourself:

crystal /examples/client.cr -- --text="Hola!" -r <Your Telegram ID>

Please not that you have to contact the bot at least once so it can send you messages.

Worker

The worker periodically checks for new broadcasts and handles them:

require "tele-broadcast/worker"
require "tele-broadcast/repositories/redis"

logger = Logger.new(STDOUT).tap(&.level = Logger::DEBUG)
repo = Tele::Broadcast::Repositories::Redis.new(Redis.new, logger, "example_bot:broadcast:") # Don't forget to add a colon in the end of namespace

worker = Tele::Broadcast::Worker.new("BOT_API_TOKEN", repo, logger)
worker.run

# =>  INFO -- : Tele::Broadcast::Worker worker is running!
# =>  INFO -- : Started broadcasting payload #1 to 2 recipients...
# => DEBUG -- : Recipient 116543174 has blocked the bot, skipping
# => DEBUG -- : Sending request #727 to 155633478...
# => DEBUG -- : Delivered request #727 in 0.29s
# =>  INFO -- : Done broadcasting payload #1 in 0.29s!

Try it yourself:

crystal /examples/worker.cr -- -t <BOT_API_TOKEN>

Development

There are tests! So please run crystal spec while developing.

Contributing

  1. Fork it ( https://github.com/vladfaust/tele-broadcast.cr/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

More Repositories

1

unity-wakatime

WakaTime plugin for Unity ⏱
C#
116
star
2

crystalworld

RealWorld back-end API implementation 👍
Crystal
43
star
3

migrate.cr

A database migration solution 🚜
Crystal
31
star
4

i18n.cr

Internationalization shard 🌍
Crystal
24
star
5

jbuilder-json_api

Jbuilder meets jsonapi.org specifications
Ruby
23
star
6

http-multiserver.cr

Mount multiple web applications 🚦
Crystal
23
star
7

http-params-serializable

The HTTP params parsing module for Crystal 🤓
Crystal
20
star
8

tarantool.cr

The Tarantool driver (a.k.a. connector) 🕷
Crystal
19
star
9

mini_redis

A light-weight low-level Redis client for Crystal ♨️
Crystal
18
star
10

validations.cr

Validations module for Crystal ✅
Crystal
13
star
11

tele.cr

A convenient Telegram Bot framework 🤖
Crystal
13
star
12

callbacks.cr

Expressive callbacks module for Crystal 🚉
Crystal
12
star
13

background

Fast background job processing
Crystal
11
star
14

stripe.cr

🚧 WIP 🚧 Stripe API wrapper 💳
Crystal
7
star
15

onyx-http-deprecated

Deprecated Onyx module
Crystal
6
star
16

cake-bake

Bake Cakefile into native Crystal code 🍞
Crystal
5
star
17

time-span-humanize

Time::Span#humanize method
Crystal
5
star
18

crack

Alternative Crystal HTTP server implementation
Crystal
5
star
19

timer.cr

A versatile timer module ⏲
Crystal
4
star
20

realworld-benchmark

RealWorld Benchmark
Crystal
3
star
21

onyx-40-loc-distributed-chat

Distributed websocket chat in 40 lines of code
JavaScript
2
star
22

time_format.cr

Time spans formatting made simple ⌚️
Crystal
2
star
23

Expense-Manager-2

Java
1
star
24

attribute_enum

Rails-like enums with ease
Ruby
1
star