pypandorabot
is a python API for Pandorabots
This code is written in python 2.7. The modules used are:
- urllib2
- urllib
- xmltodict
Soon on PyPi.
import pypandorabot
you have to specify the bot id provided by the pandorabot as parameter for the objext Pandorabot In this case a new session is created:
bot_id = "f5d922d97e345aa1" #A.L.I.C.E.
bot = pypandorabot.Pandorabot(bot)
If the bot is missing (wrong id) a MissingBot
exception is raised.
Message are sent using the talk(string) method:
bot.talk("Hello bot, how are you?")
you can also specify a custom id, a parameter used like a session id in order to keep track of the messages previously exchanged:
cust = "e40fcd461e360607"
bot = pypandorabot.Pandorabot(bot,custId)
Started a chat you can retrieve the current custom id using:
bot.getCustId()
The custom id it's generated by the server and it's auto stored by the code, however if you want you can set it to None by calling the method reset():
bot.reset()
import pypandorabot
bot_id = "f5d922d97e345aa1"
cust = "e40fcd461e360607"
bot = pypandorabot.Pandorabot(bot_id)
print bot.talk("My name is Jason")
print bot.talk("whats my name?")
print bot.getCustId()
print bot.talk("whats my name?")
bot.reset()
print bot.getCustId()
print bot.talk("whats my name?")
print bot.getCustId()