Skip to content

Extensions

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

Available extensions

Program-Y ships with a number of extensions which are additional grammars that provide a specific set of questions and answers. A number of the extensions such as Banking, Energy etc provide a framework to build your own more detailed platform specific to the extension, whereas the more generic ones such as Weather and News provide fully constructed grammars and a range of questions and answers.

Building Your Own Extension

Inherit from the abstract base class

    programy.extensions.Extension

This class provides a single method to implement, execute, which takes bot, clientid and data as parameters. The data parameter is a space separated set of data that comes directly from the grammar calling the extension

    class Extension(object):
        __metaclass__ = ABCMeta

        @abstractmethod
        def execute(self, bot, clientid, data):
            raise NotImplemented()

An extension is called from within an 'extension' template tag. All text contained as child elements are passed to the Python method 'execute' as a string of words separated by spaces in the data parameter.

The execute method returns the same, a string of words separated by spaces. This is typically passed through an srai tag the result returned words matched to a suitable pattern.

<category>
    <pattern>
        BANK BALANCE *
    </pattern>
    <template>
        <srai>
            SHOW_BALANCE
            <extension path="programy.extensions.banking.balance.BankingBalanceExtension">
                <star />
            </extension>
        </srai>
    </template>
</category>
Clone this wiki locally