Initial Commit

master
TechieDamien 2021-11-03 11:57:55 +00:00
parent e1d3f55153
commit 4d2a4dacdd
2 changed files with 84 additions and 1 deletions

View File

@ -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.
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.

17
__init__.py Normal file
View File

@ -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))