Skip to content
Broadcasting for Tele 📢
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
spec
src
.editorconfig
.gitignore
.travis.yml
LICENSE
README.md
shard.yml

README.md

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

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.