Skip to content

External_Services

Keith Sterling edited this page Sep 22, 2017 · 10 revisions

Overview

External services are those services which can be called from the sraix tag. How to use the tag is described in SRAIX Tag. The sraix tag was originally designed to only called other bots but I felt that this was a short-sighted limitation as the interface is about making a REST API call to an appropriate end point. Therefore with a little refactoring and better documentation you can use the sraix tag to call any external service exposed as a REST GET or POST endpoint.

Available External Services

The list of available endpoints that have been implemented and tested with Program-Y are currently

Building Your Own Service

Each external service is represented by a Python Object which must inherit from

 programy.services.service.Service

This is a simple class which requires the implementation of a single method ask_question.

class Service(object):
    __metaclass__ = ABCMeta

    def __init__(self, config: BrainServiceConfiguration):
        self._config = config

    @property
    def configuration(self):
        return self._config

    def load_additional_config(self, service_config):
        pass

    @abstractmethod
    def ask_question(self, bot, clientid: str, question: str):
        """
        Never knowingly Implemented
        """

Configuration is down by adding an entry to the services section of config.yaml as follows

        myservice:
            classname: programy.services.myservice.StatusCheck
            url: http://myservice.com/api/statuscheck

When a sraix tag is encountered the the class defined in classname is loaded and ask_question() is called with question contained in the node.

<category>
    <pattern>CHECK STATUS OF *<pattern>
    <template>
        Status of <star /> is <sraix service="myservice"><star/></sraix>
    </template>
</category>
Clone this wiki locally