Package: eddie
eddieis a library you can use to create your own chat bots in
seconds.This is a very young library, any request/suggestion/help will be very
appreciated. For them, create an issue or contact me!InstallYou can install eddie using just pip:$pipinstalleddieIf you want the latest version download this repository in your project or
using pip:$pipinstallgit+https://github.com/greenkey/eddie.gitUsageYou have to define your bot class, extending the defaultBotclass:>>>fromeddie.botimportBot>>>classMyBot(Bot):...pass...>>>b=MyBot()>>>b<__main__.MyBotobjectat0x7f16e79f3940>Of course you’ll want to define some bahaviour, the following chapters
teach you how to do it.Defining a default response>>>fromeddie.botimportBot>>>classMyBot(Bot):...defdefault_response(self,in_message):...# setting echo as default response...returnin_message...>>>b=MyBot()>>>b.process("Hello!")'Hello!'>>>b.process("Goodbye!")'Goodbye!'Defining commandsJust define a method of your Bot class using thecommanddecorator.>>>fromeddie.botimportBot,command>>>classMyBot(Bot):...@command...defhello(self):...return"hello!"...>>>bot=MyBot()>>>bot.process("/hello")# the default command prepend is "/"'hello!'Defining interfacesA bot running in local would be pretty useless, isn’t it?The simplest interface we can give to our bot is the http one.>>>fromeddie.botimportBot>>>fromeddie.endpointsimportHttpEndpoint>>>classMyBot(Bot):...defdefault_response(self,in_message):...returnin_message...>>>bot=MyBot()>>>ep=HttpEndpoint()>>>bot.add_endpoint(ep)>>>bot.run()Then you can send message to the bot using simple GET requests:http://localhost:8000/process?in_message=helloNote: default port is 8000, if it is already used,HttpEndpointwill
use the first free port after 8000 (8001, 8002…).The output using the example will be a json with the message:{"out_message": "hello"}TelegramYes, you can easily connect your bot with the Telegram API, thanks to
thepython-telegram-botlibrary.You don’t have to worry about nothing, except getting a token from theBotFatherand passing it
to your bot.>>>fromeddie.botimportBot>>>fromeddie.endpointsimportTelegramEndpoint>>>classMyBot(Bot):...defdefault_response(self,in_message):...returnin_message...>>>bot=MyBot()>>>ep=TelegramEndpoint(...token='123:ABC'...)>>>bot.add_endpoint(ep)>>>bot.run()TwitterIt’s not a proper bot framework, but witheddieyou can have a bot in
Twitter too, thanks to thetweepylibrary.Just follow the instrunction onhow to create a Twitter App, get all the tokens and use them to instantiate theTwitterEndpoint.>>>fromeddie.botimportBot>>>fromeddie.endpointsimportTwitterEndpoint>>>classMyBot(Bot):...defdefault_response(self,in_message):...returnin_message...>>>bot=MyBot()>>>ep=TwitterEndpoint(...consumer_key='your consumer_key',...consumer_secret='your consumer_secret',...access_token='your access_token',...access_token_secret='your access_token_secret'...)>>>bot.add_endpoint(ep)>>>bot.run()LoggingThis library uses the logging module. To set up logging to standard
output, put:importlogginglogging.basicConfig(level=logging.DEBUG)at the beginning of your script.Get involvedIf you want to contribute, download the repository, then:$virtualenv~/.venv/eddie# not required but highly suggested$source~/.venv/eddie/bin/activate$pipinstall-rrequirements-dev.txt# install all the requirements$pytest