-
Notifications
You must be signed in to change notification settings - Fork 135
OOB
Keith Sterling edited this page Jul 31, 2017
·
8 revisions
import xml.etree.ElementTree as ET
class OutOfBandProcessor(object):
def __init__(self):
return
# Override this method to extract the data for your command
# See actual implementations for details of how to do this
def parse_oob_xml(self, oob: ET.Element):
return
# Override this method in your own class to do something
# useful with the command data
def execute_oob_command(self, bot, clientid):
return ""
def process_out_of_bounds(self, bot, clientid, oob):
if self.parse_oob_xml(oob) is True:
return self.execute_oob_command(bot, clientid)
else:
return ""
As an example, here we have an Out Of Band capability to send an email from your client device, the OOB AIML is as follows
<oob>
<email>
<to>recipient</to>
<subject>subject text</subject>
<body>body text</body>
</email>
</oob>
The class that implements this would look similar to the following, the only addition to make this work would be to subclass the class before and implement the execute_oob_command() method to send and email
class EmailOutOfBandProcessor(OutOfBandProcessor):
def __init__(self):
OutOfBandProcessor.__init__(self)
self._to = None
self._subject = None
self._body = None
def parse_oob_xml(self, oob: ET.Element):
for child in oob:
if child.tag == 'to':
self._to = child.text
elif child.tag == 'subject':
self._subject = child.text
elif child.tag == 'body':
self._body = child.text
else:
logging.error ("Unknown child element [%s] in email oob"%(child.tag))
if self._to is not None and \
self._subject is not None and \
self.body is not None:
return True
logging.error("Invalid email oob command")
return False
def execute_oob_command(self, bot, clientid):
logging.info("EmailOutOfBandProcessor: Emailing=%s", self._to)
return ""
To make this work, you add the following configuration to config.aiml
oob:
email:
classname: programy.utils.oob.email.EmailOutOfBandProcessor
For more information on configuration settings for Out of Band processing, see Out of Bands Configuration
Email: [email protected] | Twitter: @keiffster | Facebook: keith.sterling | LinkedIn: keithsterling | My Blog
- Home
- Background
- Guiding Principles
- Reporting an Issue
- Installation
- You And Your Bot
- Bots
- Clients
- Configuration
- AIML
- Sentence Splitting
- Natural Langauge Processing
- Normalization
- Spelling
- Sentiment Analysis
- Translation
- Security
- Hot Reload
- Logging
- Out of Band
- Multi Language
- RDF Support
- Rich Media
- Asynchronous Events
- Triggers
- External Services
- Dynamic Sets, Maps & Vars
- Extensions
- Pre & Post Processors
- Custom Nodes
- The Brain Tree
- Utilities
- Building It Yourself
- Creating Your Own Bot
- Contributing
- Performance Testing
- FAQ
- History
- Website