Giter VIP home page Giter VIP logo

unni's Introduction

unni

unni is a Telegram Bot that gives info about events from isamuni

unni is the Sicilian word for where. That is one of the main questions people ask about events: where is it? unni, however, provides more information about events than just where that happen.

unni will serve the events data from isamuni.

commands

This is the list of commands supported by unni

  • /help
  • /today
  • /future

We would love to have other commands, such as /topic or /city, in the future.

Running the Bot Locally

This bot is using the python-telegram-bot library.

The first step to run the bot is to install the required dependencies. You can do this via pip

$ pip install python-telegram-bot --upgrade

Then call the @BotFather within Telegram and use the /newbot command to create a new bot.

Then create a configuration file called unni.cfg that follows this template:

[source]
name = isamuni
url = http://isamuni.it/events.json

[telegram]
token = 2ThisIsGoingToBeAVeryLongTokenFromBotFatherXY

[log]
dir = logs
name = unni_bot.log

[commands]
start = start
help = aiuto, help, h
future = futuri, future
today = oggi, today
subscribe = subscribe, sub
unsubscribe = unsubscribe, unsub

[messages]
welcome = Ciao {user_name}! Io sono {bot_name}
    Usa il comando: /{help_cmd} per maggiori info su come posso aiutarti
help = Unni ti aiuterà a trovare gli eventi tech in Sicilia.
    I comandi disponibili sono:
    - /{today_cmd}
    - /{future_cmd}
    - /{sub_cmd}
    - /{unsub_cmd}
    Unni usa isamuni.it come fonte di dati
failure = Mi dispiace, ma non ho trovato eventi
today = Gli eventi di oggi sono:
future = I prossimi eventi sono:
subscribe = Grazie per esserti iscritto a unni. 
    Verrai notificato ogni {frequency} ore sugli eventi del giorno
subscribe_header = Ciao {user_name}! Se non desideri più ricevere queste notifiche,digita /{unsub_cmd}
subscribe_fail = Sei già registrato a unni
unsubscribe = Unni non ti invierà piú notifiche
unsubscribe_fail = Non ti sei mai registrato per le notifiche di unni

[subscribe]
frequency = 86400

Then run:

$ python unni.py

Now you can call your bot on telegram and have fun!

Run unni via docker and docker-compose

docker

$ docker build -t unni .
$ docker run unni

docker-compose

$ docker-compose build
$ docker-compose up -d # will start container in background

Testing the deployed Bot

You can test it by adding the unni_bot to your Telegram

Info

This project is currently maintained by the PAC Community and it is under the MIT license. Feel free to use and modify it.

unni's People

Contributors

aegroto avatar veeenz avatar

Watchers

James Cloos avatar Simone Conte avatar

Forkers

aegroto veeenz

unni's Issues

bot unresponsive because of some HTTP connection issue

2016-12-14 10:34:08,495 - urllib3.connectionpool - WARNING - Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='api.telegram.org', port=443): Read timed out. (read timeout=<object object at 0x7f9d715400d0>)",)': /bot231976650:AAG-KM1-xy-SPILHpUYgLLBSlmNHHrCIaXY/sendMessage

Using a single repeating job could make things easier

Unni is currently creating a new Job every time a user subscribes.
A different approach could be using a single repeating job, scheduled to run every 10 minutes for example, which takes from the database the list of users who need to be notified and does so.
This would make it easier to restart the bot (there's no queue to refill) and scales better.
Consider something like this: https://github.com/vigliag/vijournalbot/blob/master/main.py#L188

bot is unresponsive

2016-12-13 18:22:16,857 - root - INFO - Logger initialised
2016-12-13 18:22:16,858 - root - INFO - Starting the Unni Bot!
2016-12-13 18:22:16,865 - root - INFO - Unni Bot started!
2016-12-13 18:53:59,407 - urllib3.connectionpool - WARNING - Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='api.telegram.org', port=443): Read timed out. (read timeout=<object object at 0x7fa756eb30d0>)",)': /bot3453242650:AAG-KM1-xy-SPILHpUYgLLBSCODECODECODE/sendMessage
2016-12-13 19:23:35,072 - root - INFO - Logger initialised
2016-12-13 19:23:35,072 - root - INFO - Starting the Unni Bot!
2016-12-13 19:23:35,073 - root - INFO - Unni Bot started!
2016-12-13 22:39:01,658 - telegram.ext.dispatcher - WARNING - A TelegramError was raised while processing the Update.
2016-12-13 22:39:01,660 - root - WARNING - Update "{'message': {'migrate_to_chat_id': 0, 'delete_chat_photo': False, 'new_chat_photo': [], 'entities': [{'length': 7, 'type': u'bot_command', 'offset': 0}], 'text': u'/futuri', 'migrate_from_chat_id': 0, 'channel_chat_created': False, 'from': {'username': u'USERNAME', 'first_name': u'NAME', 'last_name': u'SURNAME', 'type': '', 'id': 16835XXX}, 'supergroup_chat_created': False, 'chat': {'username': u'USERNAME', 'first_name': u'NAME', 'all_members_are_admins': False, 'title': '', 'last_name': u'SURNAME', 'type': u'private', 'id': 16835XXX}, 'photo': [], 'date': 1481668741, 'group_chat_created': False, 'caption': '', 'message_id': 353, 'new_chat_title': ''}, 'update_id': 388110134}" caused error "u"Bad Request: Can't parse message text: Can't find end of the entity starting at byte offset 498""
2016-12-13 22:39:17,228 - telegram.ext.dispatcher - WARNING - A TelegramError was raised while processing the Update.
2016-12-13 22:39:17,228 - root - WARNING - Update "{'message': {'migrate_to_chat_id': 0, 'delete_chat_photo': False, 'new_chat_photo': [], 'entities': [{'length': 7, 'type': u'bot_command', 'offset': 0}], 'text': u'/futuri', 'migrate_from_chat_id': 0, 'channel_chat_created': False, 'from': {'username': u'USERNAME', 'first_name': u'NAME', 'last_name': u'SURNAME', 'type': '', 'id': 16835XXX}, 'supergroup_chat_created': False, 'chat': {'username': u'USERNAME', 'first_name': u'NAME', 'all_members_are_admins': False, 'title': '', 'last_name': u'SURNAME', 'type': u'private', 'id': 16835XXX}, 'photo': [], 'date': 1481668757, 'group_chat_created': False, 'caption': '', 'message_id': 356, 'new_chat_title': ''}, 'update_id': 388110136}" caused error "u"Bad Request: Can't parse message text: Can't find end of the entity starting at byte offset 498""

Log has been anonymised

bot unresponsive because of unknown reason

2016-12-14 08:46:07,777 - root - WARNING - Update "None" caused error "Conflict: terminated by other long poll or webhook (409)"
2016-12-14 08:46:09,825 - telegram.ext.updater - ERROR - Error while getting Updates: Conflict: terminated by other long poll or webhook (409)
2016-12-14 08:46:09,841 - root - WARNING - Update "None" caused error "Conflict: terminated by other long poll or webhook (409)"
2016-12-14 08:46:11,903 - telegram.ext.updater - ERROR - Error while getting Updates: Conflict: terminated by other long poll or webhook (409)
2016-12-14 08:46:11,906 - root - WARNING - Update "None" caused error "Conflict: terminated by other long poll or webhook (409)"
2016-12-14 08:46:14,073 - telegram.ext.updater - ERROR - Error while getting Updates: Conflict: terminated by other long poll or webhook (409)
2016-12-14 08:46:14,120 - root - WARNING - Update "None" caused error "Conflict: terminated by other long poll or webhook (409)"

According to some Google results:

  • this might be due to multiple unni bot instances running at the same time
  • concurrent requests to the bot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.