Skip to content

HungryFoolishHappy/recruitment-flask-template

Repository files navigation

Dialogflow NLP experiment

This experiment emulate

  1. A chat server send a message to this server via webhook,
  2. This server should send that message to Dialogflow and it will return the intent of the message
  3. This server should search for a response in the databse and reply it back to the chat server

You will need

  • git
  • docker
  • sending HTTP request to API server with cURL or Postman
  • a language and a application server of choice, python and Flask in this case
  • a way to expose a local server to public, e.g. ngrok
  • basic understanding of ORM (Object-relational mapping), in this case SQLAlchemy. Only having general knowledge of ORM will suffice, we will only use the most basic feature in this experiment
  • basic understanding of server to server communication, webhook to be specific.

Detail steps

  1. Pull this repostory
  2. Start the server with docker (see commands below)
  3. Get your user id and save it in a variable
  4. Retrieve the service account from users/[your user id]/service_account. With curl, postman or some other means, and save it in a file (e.g. service_account.json)
  5. Expose the server to public using ngrok
  6. Register the your webhook endpoint under the chat server's users/[your user id]/webhook with a PUT request, the endpoint expect JSON body with the structure { "webhook": your web hook here }
  7. Use /users/[your user id]/simulate-actions/speaks to request the chat server to send you a message
  8. Extract the utterence from the message, and use SessionsClient form Dialogflow to resolve the intent
  9. Return { "intent": the name of the intent resolved by dialogflow } as the response of your webhook, we will treat the value in queryResult.action as the intent name
  10. Call /users/[your user id]/simulate-actions/speaks again but with { "should_validate_image_url": true } as the request body. This time after getting the intent from dialogflow, find the requested snack or drink from the database and return it as a JSON object

Files included in this repo

  • this README
  • main.py, the entry point of the server
  • Dockerfile, for creating the container to run the server
  • pyproject.toml and poetry.lock, used by poetry for installing dependencies, which is alredy handled in the Dockerfile
  • models.py, defining the SQLAlchemy models
  • databse.py, for setting up the database connection, and configuring the ORM
  • database.sqlite, storing the response you will need to send back to the chat server. Used by the ORM

Useful commands

# build the image
docker build --tag dialogflow-nlp-experiment .
# run the container (this image was running flask in development mode, it will auto-reload upon file change, manually restarting the container is not necessary)
docker run --rm -v `pwd`:/app -p 5000:5000 dialogflow-nlp-experiment

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published