From 4d2a4dacdd0bcb1d8c709f6b64a73ddad49cbf32 Mon Sep 17 00:00:00 2001 From: TechieDamien Date: Wed, 3 Nov 2021 11:57:55 +0000 Subject: [PATCH] Initial Commit --- README.md | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++- __init__.py | 17 ++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 __init__.py diff --git a/README.md b/README.md index 09c5fe0..74bc45f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,69 @@ # Opsdroid-RasaSR -Opsdroid Rasa Simple Respond is a bot that will simply respond with a randomly chosen phrase when rasa detects an intent. \ No newline at end of file +Opsdroid Rasa Simple Respond is a bot that will simply respond with a randomly chosen phrase when rasa detects an intent. This skill is completely configurable from the opsdroid config, so there is no need to touch the source code unless you want more advanced behaviour. + +## Usage + +In order to edit your opsdroid configuration, make sure you are in your opsdroid virtual environment (if applicable) and run `opsdroid config edit`. Then you can add the following yaml in order to start the bot (note that this does not include connector configurations and you may need to merge the sections here with existing sections if you already have opsdroid set up). + +``` +parsers: + rasanlu: + url: http://localhost:5005 + models-path: models + token: SUPER_SECRET_TOKEN + min-score: 0.8 + +skills: + rasa_greet: + path: '/path/to/__init__.py' + intent: 'greet' + response_options: + - 'Why, hello there!' + - "What's up, ma dude" + - "Hello!" + - "Hiya!" + - "Wazzup" + - "How ya doin?" +``` + +You can include many of skills going the the same path with different intents and response\_options in order to be able to respond to many different types of message. + +Of course, you will also need Rasa installed and running on your machine (`rasa run --enable-api --auth-token SUPER_SECRET_TOKEN`), and we will need to provide either a model or an intents file. Either way, we need an intents file. See the following example for the syntax. + +``` +version: "2.0" + +nlu: +- intent: greet + examples: | + - hey + - hello + - hi + - hello there + - good morning + - good evening + - moin + - hey there + - let's go + - hey dude + - goodmorning + - goodevening + - good afternoon + +- intent: goodbye + examples: | + - good afternoon + - cu + - good by + - cee you later + - good night + - bye + - goodbye + - have a nice day + - see you around + - bye bye + - see you later +``` + +And, again, you can add more intents here so that Rasa can recognise them. Put these intents in a file called intents.yml and Opsdroid will automatically send that to Rasa to train. diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..a4f51ee --- /dev/null +++ b/__init__.py @@ -0,0 +1,17 @@ +from opsdroid.skill import Skill +from opsdroid.matchers import match_rasanlu, match_parse +import random + +class Respond(Skill): + def __init__(self, opsdroid, config): + super().__init__(opsdroid, config) + self.intent = self.config.get("intent") + self.respond = match_rasanlu(self.intent)(self.respond) + + # This line is to add properties to respond on declaration + # as doing this in __init__ would cause an exception to be + # raised. If you don't believe me, remove it! + @match_parse("hgftgyhjknbvhgftyuihjkvhgftyuijkbjhgtyyuijhkjghfdtrytyihujkbvncgfxdtrytuyiuhkbjvbhcfdytryuhjkbvhcfdyrtuyiuhkbhj") + async def respond(self, message): + response_options = self.config.get("response_options") + await message.respond(random.choice(response_options))