| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This article is about new @codex_bot application development. Throughout this guide we build an application that can provide weather forecast for different periods of time.
For simplicity we use our modern Python SDK. We also provide instructions how to run your own production-ready @codex_bot server.
Before start you need to run @codex_bot Core (read Developer's Guide) or use our @codex_bot
If you are wondering, we have a lot of other useful @codex_bot applications to play with. Check our landing for the further information.
You can skip this step if you don't need to run MongoDB in a Docker.
The sources of our example application could be found in repository.
Now, you can run weather application with python main.py command. If everything is all right, you will get back several debug messages from Core with the prefix Received
In main.py there is an SDK initialization with values from the configuration file. self.sdk = CodexBot(APPLICATION_NAME, SERVER['host'], SERVER['port'], db_config=DB, token=APPLICATION_TOKEN)
After that, method register_commands tells Core which commands should be redirected to your application (note: this commands might be unique!).
self.sdk.register_commands([
('weather_help', 'help', CommandHelp(self.sdk)),
('weather', 'weather', CommandWeather(self.sdk)),
('cities', 'cities', CommandCities(self.sdk)),
('city', 'city', CommandCity(self.sdk)),
('rain3', 'rain3', CommandWeather(self.sdk)),
('rain10', 'rain10', CommandWeather(self.sdk))
])Handlers for each command are defined in commands directory. You can find imports in the beginning of the main.py script:
from commands.help import CommandHelp
from commands.cities import CommandCities
from commands.city import CommandCity
from commands.weather import CommandWeatherOur SDK invokes init method with payload parameter. Watch an example in the commangs/cities.py file:
class CommandCities(CommandBase):
async def __call__(self, payload):
self.sdk.log("/cities handler fired with payload {}".format(payload))
await self.sdk.send_text_to_chat(
payload["chat"],
"...message here..."
)When user inputs /cities command in the telegram chat with bot, you'll receive a debug message with the payload into your terminal:
logging.py :17 debug() /cities handler fired with payload {'command': 'cities', 'params': '', 'chat': 'RXRI6S0N', 'user': 'VZXTDQ44'}Ask a question or report a bug on the create issue page.
Know how to improve SDK? Fork it and send a pull request.
We are small team of passionate web-developers consisting of IFMO University students and graduates located in St. Petersburg, Russia. Fell free to give us a feedback on team@ifmo.su
| Back | FazBrowse Home | New Git URL |