-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of gitlab.com:pencillabs/ej/ej-bot into main
- Loading branch information
Showing
18 changed files
with
427 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
RASA_X_VERSION=<rasa_x_version> | ||
RASA_VERSION=<rasa_version> | ||
RASA_TOKEN=c4TdROQ4sVTc8JUlFLQFvQ | ||
RASA_X_TOKEN=1PJkHOcdUCd21Tnw7T1oTg | ||
PASSWORD_SALT=Mt6gU4mudBeT8B9tgJVfeg | ||
JWT_SECRET=p5J/3qFcHEDl9LC66mQapQ | ||
RABBITMQ_PASSWORD=LzkOXZbnGesQKKHFnh7wmg | ||
DB_PASSWORD=PZQwYSewjII2/zG2+Kmn3g | ||
REDIS_PASSWORD=D3gO8RnXPbnyZ2UyYaHNhw | ||
RASA_TOKEN= | ||
RASA_X_TOKEN= | ||
PASSWORD_SALT= | ||
RABBITMQ_PASSWORD= | ||
DB_PASSWORD= | ||
REDIS_PASSWORD= | ||
RASA_TELEMETRY_ENABLED=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .api import API | ||
from .user import User |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import os | ||
import requests | ||
from .user import User | ||
|
||
HEADERS = { | ||
"Content-Type": "application/json", | ||
} | ||
VOTE_CHOICES = {"Pular": 0, "Concordar": 1, "Discordar": -1} | ||
HOST = os.getenv("EJ_HOST") | ||
API_URL = f"{HOST}/api/v1" | ||
REGISTRATION_URL = f"{HOST}/rest-auth/registration/" | ||
VOTES_URL = f"{API_URL}/votes/" | ||
|
||
|
||
def conversation_url(conversation_id): | ||
return f"{API_URL}/conversations/{conversation_id}/" | ||
|
||
|
||
def conversation_random_comment_url(conversation_id): | ||
return f"{conversation_url(conversation_id)}random-comment/" | ||
|
||
|
||
def user_statistics_url(conversation_id): | ||
return f"{conversation_url(conversation_id)}user-statistics/" | ||
|
||
|
||
def user_comments_route(conversation_id): | ||
return f"{conversation_url(conversation_id)}user-comments/" | ||
|
||
|
||
def user_pending_comments_route(conversation_id): | ||
return f"{conversation_url(conversation_id)}user-pending-comments/" | ||
|
||
|
||
def auth_headers(token): | ||
headers = HEADERS | ||
headers["Authorization"] = f"Token {token}" | ||
return headers | ||
|
||
|
||
class API: | ||
def create_user(sender_id, name="Participante anônimo", email=""): | ||
user = User(sender_id, name, email) | ||
response = requests.post( | ||
REGISTRATION_URL, | ||
data=user.serialize(), | ||
headers=HEADERS, | ||
) | ||
user.token = response.json()["key"] | ||
return user | ||
|
||
def get_next_comment(conversation_id, token): | ||
url = conversation_random_comment_url(conversation_id) | ||
response = requests.get(url, headers=auth_headers(token)) | ||
comment = response.json() | ||
comment_url_as_list = comment["links"]["self"].split("/") | ||
comment["id"] = comment_url_as_list[len(comment_url_as_list) - 2] | ||
return comment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
import json | ||
import jwt | ||
|
||
|
||
class User(object): | ||
def __init__(self, rasa_id, name="", email=""): | ||
self.name = name | ||
self.display_name = "" | ||
self.stats = {} | ||
if email: | ||
self.email = email | ||
self.password = self.email | ||
self.password_confirm = self.email | ||
else: | ||
secret = os.getenv("JWT_SECRET") | ||
encoded_id = jwt.encode({"rasa_id": rasa_id}, secret, algorithm="HS256") | ||
self.email = f"{encoded_id}[email protected]" | ||
self.password = f"{encoded_id}-rasa" | ||
self.password_confirm = f"{encoded_id}-rasa" | ||
|
||
def serialize(self): | ||
return json.dumps(self.__dict__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,9 @@ nlu: | |
- correto | ||
- afirmativo | ||
- concordar | ||
- uhum | ||
- com certeza | ||
- claro | ||
- intent: disagree | ||
examples: | | ||
|
@@ -35,6 +38,7 @@ nlu: | |
- discordo | ||
- discordar | ||
- não concordo | ||
- não quero | ||
- intent: pass | ||
examples: | | ||
|
@@ -44,6 +48,28 @@ nlu: | |
- passa | ||
- próxima pergunta | ||
- intent: email | ||
examples: | | ||
- meu email é [email protected] | ||
- [email protected] | ||
- email: [email protected] | ||
- meu email: [email protected] | ||
- intent: invalid_email | ||
examples: | | ||
- @wlor | ||
- @algumacoisa. | ||
- @nome. | ||
- roberto@email | ||
- nome@algo | ||
- roberto@ | ||
- maria@ | ||
- @joao | ||
- @joao. | ||
- meu email é @nome | ||
- email: @maria | ||
- meu email: roberto@ | ||
- intent: out_of_context | ||
examples: | | ||
- 4 + 2 = ? | ||
|
@@ -60,3 +86,4 @@ nlu: | |
- tempo | ||
- stop | ||
- sair | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.