With positive feedback we've received in our Bitcoitalk thread, the developers of Bethereum would like to share their first guide.
To stay up-to-date with our contributions to the crypto-community join our Telegram group
This is a guide for the crypto community, all current and future Crypto project developers and any other enthusiasts. I'd like to credit python-telegram-bot for creating the wrapper used in the guides.
You can install or upgrade python-telegram-bot with:
$ pip install python-telegram-bot --upgrade
Or you can install from source with:
$ git clone https://github.com/python-telegram-bot/python-telegram-bot --recursive
$ cd python-telegram-bot
$ python setup.py install
Simple way to communicate the most important information to your members and supporters, such as:
- Social Media links
- News
- PR contacts
- Any repetative questions
- Telegram user verification
Open up @Botfather on Telegram to create your new bot and receive the API token.
The python-telegram-bot wrapper we'll be using works the following way:
- You define functions to tell your bot what to do when someone writes a command beginning with "/" or a message.
- By adding CommmandHandlers or MessageHandlers you link these functions to the commands or messages written by a user.
Note: see the documentation for CommandHandlers and MessageHandlers.
Importing modules:
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import logging
Setting up the logging module:
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
Defining the start function:
def start(bot, update):
bot.send_message(chat_id=update.message.chat_id, text='Hello ' + update.message.from_user['first_name'] + '!' '\nI am the *BethereumBot*, click on /help to find out how I can assist you.' , parse_mode = 'Markdown')
Defining the help function:
def help(bot, update):
update.message.reply_text("Currently I can't help you with anything, talk to my developers and tell them to add more functions and CommandHandlers!")
Function for possible errors caused by updates:
def error(bot, update, error):
logger.warning('Update "%s" caused error "%s"', update, error)
Defining the unkown function:
def unknown(bot, update):
bot.send_message(chat_id=update.message.chat_id, text="Sorry, I didn't understand that command, please click at /help to see a list of all available commands.")
Note: Look at the following documentation for possible Bot actions.
Setting up the Updater:
updater = Updater(token='123456:AAABBCCDDEEEFFFGGHHHIIIJJKKLL') # Copy the Token from the Botfather here
dp = updater.dispatcher
You have to link the functions declared above with commands or messages written by a user:
dp.add_handler(CommandHandler('start', start)) # Runs the start function declared above when a user writes /start
dp.add_handler(CommandHandler('help', help)) # Runs the help function declared above when a user writes /help
dp.add_handler(MessageHandler(Filters.command, unknown)) # Runs the unkown function declared above when a user writes an unkown command
dp.add_error_handler(error) # Runs the error function declared above when there are any errors in the backend
The following line of code will tell the bot to start getting updates from Telegram:
updater.start_polling()
There are many ways of doing the same thing, maybe you've noticed we used bot.send_message
in one function and update.message.reply_text
in another, therefore we advise you to read the documentation provided for the wrapper.
We're going to add a guide for the deployment of your bot soon!