Can Rasa chatbot initiate a conversation? - rasa-nlu

I'm planning to deploy the bot based on rasa with a monitoring engine. So if something goes wrong, I would like bot to start the conversation with a specific user. Is that possible?

An easy way to do so, would be to send a user message from your monitoring system to your input channel. So you basically mimic the user initiating the conversation. Note that I directly specify the intent using the / as prefix.
Start Rasa Core with the REST api exposed:
python -m rasa_core.run -d models --enable-api
Then you can send messages to it, e.g.:
curl --request POST \
--url http://localhost:5005/webhooks/rest/webhook \
--header 'content-type: application/json' \
--data '{
"sender": "<sender_id_of_your_user>",
"message": "/inform_about_failure"
}'

#Tobias's solution is the "old way" still valid to manage external events in a pull-based chatbot engine (not just RASA), when we want to push notifications to sender_id.
With the current RASA release, to run the RASA Core server the cli command is:
rasa run --debug --enable-api -m models
And the curl request #Tobias specified is still valid with current RASA version:
curl --request POST \
--url http://localhost:5005/webhooks/rest/webhook \
--header 'content-type: application/json' \
--data '{
"sender": "<sender_id_of_your_user>",
"message": "/inform_about_failure"
}'
On the other hand, the suggested way by RASA now (version 1.9.7), is to use external events management.
That way you can specify also the entities along with the intent to be triggered, as the example shows:
curl \
-H "Content-Type: application/json" \
-X POST \
-d '{"name": "EXTERNAL_dry_plant", "entities": {"plant": "Orchid"}}' \
http://localhost:5005/conversations/<sender_id_of_your_user>/trigger_intent
BTW in RASA, sender_id and conversation_id are different names for the same thing.

Definitely. But rasa_nlu got nothing to do with this, you will be sending a push_messagefrom your backend to the chat client from there rasa_nlu picks up the conversation.

Related

How to create local "copy" of remote Hasura server?

I want to set up a dev environment of Hasura on my local machine, that replicates my existing production (same tables, same schema, same data).
What are the required steps to achieve this task?
I've found this process to work well.
Create a clean empty local postgresql database and Hasura instance. To update an existing local database, drop it and recreate it.
Dump the schema and data from your existing Hasura server (as per the answer by #protob, but with clean_output set so that manual changes to the output do not have to be made. See pgdump for details.
curl --location --request POST 'https://example.com/v1alpha1/pg_dump' \
--header 'Content-Type: application/json' \
--header 'X-Hasura-Role: admin' \
--header 'Content-Type: text/plain' \
--header 'x-hasura-admin-secret: {SECRET}' \
--data-raw '{ "opts": ["-O", "-x","--inserts", "--schema", "public"], "clean_output": true}' > hasura-db.sql
Import the schema and data locally:
psql -h localhost -U postgres < hasura-db.sql
The local database has all the migrations because we copied the latest schema, so just mark them as applied:
# A simple `hasura migrate apply --skip-execution` may work too!
for x in $(hasura migrate status | grep "Not Present" | awk '{ print $1 }'); do
hasura migrate apply --version $x --skip-execution
done
# and confirm the updated status
hasura migrate status
Now finally apply the Hasura metadata using the hasura CLI:
hasura metadata apply
Enjoy your new instance!
Backup the database.
Run Hasura with the database.
Make sure Hasura metadata is synced.
Hasura has a special endpoint for executing pg_dump on the Postgres instance.
Here is a sample CURL request:
curl --location --request POST 'https://your-remote-hasura.com/v1alpha1/pg_dump' \
--header 'Content-Type: application/json' \
--header 'X-Hasura-Role: admin' \
--header 'Content-Type: text/plain' \
--data-raw '{
"opts": ["-O", "-x","--inserts", "--schema", "public"]
}'
It outputs the schema and data in psql format.
You can use a tool such as Postman for convenience to import, test and run the CURL query.
Please follow the pg_dump documentation to adjust needed opts.
i.e. the above query uses "--inserts" opt, which produces "INSERT INTO" statements in the output.
The output can be copied, pasted and imported directly to Hasura Panel SQL Tab ("COPY FROM stdin" statements result in errors when inserted in the panel).
http://localhost:8080/console/data/sql
Before import, comment out or delete the line CREATE SCHEMA public; from query, because it already exists.
You also have to select tables and relations to be tracked, during or after executing the query.
If the amout of data is bigger, it might be better to use CLI for import.

GraphiQL - upload file

How can we upload files using in-browser GraphQL IDE GraphiQL, is that even possible ? (apart from base64 encoded string)
Once I have the file stream / file contents I can create a mulipart request and store on DB or some object-storage service.
But I am not able to figure it out how to provide the file input / how the schema would look like. Is it better to use graphql-upload with Curl request. Please suggest which is the optimal solution.
I was able to upload a file in my mutation input using Altair. You can use the Add files button to upload a file, then use the upload name on your mutation.
Guys just try Altair, saved me a lot of trouble and time. It has extension for chrome too, just like Apollo playground or graphiql, but with file upload option underneath the variables option.
Currently GraphIQL does not support file uploads. You can use an API tool to do this such as Postman, Insomnia or plan old cURL. The important distinction is that it needs to be a multi-part form upload.
Example request:
curl --request POST \
--url http://localhost:4000/ \
--header 'accept: application/json' \
--header 'accept-encoding: gzip, deflate, br' \
--header 'connection: keep-alive' \
--header 'dnt: 1' \
--header 'origin: http://localhost:4000' \
--form 'operations={"query": "mutation UploadFile($file: Upload!) { uploadFile(file: $file)}", "variables": { "file": null } }' \
--form 'map={ "nFile": ["variables.file"] }' \
--form nFile=#/tmp/testfile
Substitute /tmp/testfile in the request above with a path to the file you want to upload.

Spring boot and RAML

I tried to build and run this project
https://github.com/adorsys/raml-springboot-example
I build the project as right click and Maven install.That time raml-springboot-impl.jar is not generating under raml-springboot-impl project.
Do you have any idea about this.
Try to type or copy+paste the following commands in the terminal/bash as shown in the git repos README.md:
(I'll post my example from Mac, you'll probably have to modify it sensibly)
cd to the repo-s root:
cd /Users/username/Documents/RAML/raml-springboot-example
generate the package:
mvn clean package
run project:
java -jar raml-springboot-impl/target/raml-springboot-impl.jar
Create a new Todo:
curl -i -X POST -H 'Content-Type: application/json' -d '{ "task": "Design the API", "priority": 1 }' localhost:8080/api/todos
List all Todos
curl -i -H 'Accept: application/json' localhost:8080/api/todos
Get one Todo by id
curl -i -H 'Accept: application/json' localhost:8080/api/todos/1
If you feel more comfortable if you can see stuff in the browser, you can just paste the last two links in Chrome or whatever you're using ;)
Also, you can try https://www.getpostman.com/ for testing endpoints that accept other than 'GET' requests (like the first one here) ;)

Parse server response "Unexpected token"

I'm working on putting a Parse Server on Heroku. I'm using this app:
https://github.com/ParsePlatform/parse-server-example
Uploading to heroku using this guide:
https://devcenter.heroku.com/articles/getting-started-with-nodejs
I've updated the db and server URLs in the parse server code, and everything uploads and deploys properly. However, when I attempt to use cURL to test the server as indicated in this guide:
https://github.com/ParsePlatform/parse-server
I get the following error:
{"error":"Unexpected token '"}
I have copied and pasted the cURL command, modified for my url:
curl -X POST -H "X-Parse-Application-Id: myAppId" -H "Content-Type: application/json" -d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' http://my-app-name.herokuapp.com/parse/classes/GameScore
Heroku logs show the request coming in (so I know it's going to the right place) but no errors. I'm deploying from Windows 7, if that matters. This is my first experience with heroku and parse server so I'm kind of flying blind. Anybody see the problem?
Try to invert simple quote to double quote for your POST data field, it's work for me :
#here : "{'score':1337,'playerName':'Sean Plott','cheatMode':false}"
curl -X POST -H "X-Parse-Application-Id: myAppId" -H "Content-Type: application/json" -d "{'score':1337,'playerName':'Sean Plott','cheatMode':false}" http://my-app-name.herokuapp.com/parse/classes/GameScore
instead
#here : '{"score":1337,"playerName":"Sean Plott","cheatMode":false}'
curl -X POST -H "X-Parse-Application-Id: myAppId" -H "Content-Type: application/json" -d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' http://my-app-name.herokuapp.com/parse/classes/GameScore
I had that issue - for me the fix was is I was using a restApi key which is no longer needed in the Parse-Server.
It was also affecting my s3 adapter - was not allowing me to upload any images through dashboard.
I removed the restApi key and everything started working.

Subscribing multiple installations to a channel

I have a list of parse installations for push notifications.
I would like to add those installations to a channel, so that I can target the push notifications to those channels.
I see that it can be done like so:
curl -X PUT
-H "X-Parse-Application-Id: application_id"
-H "X-Parse-REST-API-Key: rest_api_key"
-H "X-Parse-Session-Token: session_token"
-H "Content-Type: application/json"
{
"deviceType": "ios",
"deviceToken": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
"channels": {"__op":"AddUnique","objects":["foo"]}
}
https://api.parse.com/1/installations/installation_object_id
But I store the installationId on my system, not the objectId. Would one be able to perform this same operation using only the installation IDs? Perhaps using a query.

Resources