diff --git a/.formatter.exs b/.formatter.exs new file mode 100644 index 0000000..525446d --- /dev/null +++ b/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ccae7ba --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,28 @@ +--- + name: CI + + on: + pull_request: + branches: master + + env: + PROJECTS_INFO: W3t9XQ== + GOOGLE_CREDENTIALS: W3t9XQ== + + jobs: + build-and-test: + name: Build and test + runs-on: ubuntu-latest + container: elixir:1.14-alpine + steps: + - uses: actions/checkout@v2 + - name: Install build dependencies + run: | + apk add --update bash openssl git + mix local.hex --force && mix local.rebar --force + - name: Install elixir dependencies + run: mix deps.get + - name: Run CI Tests + env: + MIX_ENV: test + run: mix ci \ No newline at end of file diff --git a/.github/workflows/publish-hexpm.yml b/.github/workflows/publish-hexpm.yml new file mode 100644 index 0000000..8b9b42a --- /dev/null +++ b/.github/workflows/publish-hexpm.yml @@ -0,0 +1,30 @@ +--- + name: Publish to hex.pm + + on: + push: + tags: + - "*" + + env: + PROJECTS_INFO: W3t9XQ== + GOOGLE_CREDENTIALS: W3t9XQ== + + jobs: + publish-hexpm: + name: publish to hex.pm + runs-on: ubuntu-latest + container: elixir:1.14-alpine + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: | + apk add --update bash openssl git + mix local.hex --force && mix local.rebar --force + - name: Install elixir dependencies + run: mix deps.get + - name: publish to hex.pm + run: mix hex.publish --yes + env: + HEX_API_KEY: ${{ secrets.HEX_KEY_PUBLISH }} + \ No newline at end of file diff --git a/config/config.exs b/config/config.exs index c64edf0..5b5397f 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,6 +1,6 @@ # This file is responsible for configuring your application # and its dependencies with the aid of the Mix.Config module. -use Mix.Config +import Config # This configuration is loaded before any dependency and is restricted # to this project. If another project depends on this project, this @@ -29,4 +29,4 @@ use Mix.Config # # import_config "#{Mix.env}.exs" -import_config "#{Mix.env}.exs" +import_config "#{Mix.env()}.exs" diff --git a/config/dev.exs b/config/dev.exs index 4461e28..bdfae35 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -1,6 +1,6 @@ -use Mix.Config +import Config config :flowex, host: System.get_env("DIALOGFLOW_URL") -config :flowex, projects_info: System.get_env("PROJECTS_INFO") |> File.read! +config :flowex, projects_info: System.get_env("PROJECTS_INFO") |> Base.decode64!() -config :goth, json: System.get_env("GOOGLE_CREDENTIALS") |> File.read! +config :goth, json: System.get_env("GOOGLE_CREDENTIALS") |> Base.decode64!() diff --git a/config/prod.exs b/config/prod.exs index 9c87c61..33d3811 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -1,6 +1,6 @@ -use Mix.Config +import Config config :flowex, host: "${DIALOGFLOW_URL}" -config :flowex, project_info: "${PROJECTS_INFO}" +config :flowex, project_info: "${PROJECTS_INFO}" |> Base.decode64!() -config :goth, json: "${GOOGLE_CREDENTIALS}" |> File.read! +config :goth, json: "${GOOGLE_CREDENTIALS}" |> Base.decode64!() diff --git a/config/test.exs b/config/test.exs index ae0edff..63d37c7 100644 --- a/config/test.exs +++ b/config/test.exs @@ -1,14 +1,18 @@ -use Mix.Config +import Config config :flowex, host: "api.dialogflow.com" -config :flowex, projects_info: "[\n{\n\"email\": \"client-access@lbot-8992.iam.gserviceaccount.com\"" <> - ",\n\"id\":\"lbot-170198\"\n}\n]\n" + +config :flowex, + projects_info: + "[\n{\n\"email\": \"client-access@lbot-8992.iam.gserviceaccount.com\"" <> + ",\n\"id\":\"lbot-170198\"\n}\n]\n" config :goth, - json: "[{\n \"type\": \"test_service_account\",\n \"project_id\": "<> - "\"test_project\",\n \"private_key_id\": \"0000\",\n \"private_key\""<> - ": \"-----BEGIN PRIVATE KEY-----\\ntestPrivateKey\\n-----END PRIVATE KEY-----\\n\""<> - ",\n \"client_email\": \"resuelve-bot-api@test_project.test.com\",\n "<> - " \"client_id\": \"0000\",\n \"auth_uri\": \"fakeurl\",\n \"token_uri\":"<> - " \"fakeurl\",\n \"auth_provider_x509_cert_url\": \"fakeurl\",\n "<> - "\"client_x509_cert_url\": \"fakeurl\"\n}]\n" + json: + "[{\n \"type\": \"test_service_account\",\n \"project_id\": " <> + "\"test_project\",\n \"private_key_id\": \"0000\",\n \"private_key\"" <> + ": \"-----BEGIN PRIVATE KEY-----\\ntestPrivateKey\\n-----END PRIVATE KEY-----\\n\"" <> + ",\n \"client_email\": \"resuelve-bot-api@test_project.test.com\",\n " <> + " \"client_id\": \"0000\",\n \"auth_uri\": \"fakeurl\",\n \"token_uri\":" <> + " \"fakeurl\",\n \"auth_provider_x509_cert_url\": \"fakeurl\",\n " <> + "\"client_x509_cert_url\": \"fakeurl\"\n}]\n" diff --git a/lib/flowex.ex b/lib/flowex.ex index 9422ba6..06213ad 100644 --- a/lib/flowex.ex +++ b/lib/flowex.ex @@ -14,10 +14,13 @@ defmodule Flowex do case HTTPoison.request(method, url, _body(body), _headers(email)) do {:ok, %HTTPoison.Response{status_code: status, body: body}} when status in 200..299 -> {:ok, Poison.decode!(body)} + {:ok, %HTTPoison.Response{status_code: status, body: body}} when status in 400..499 -> {:error, Poison.decode!(body)} + {:ok, %HTTPoison.Response{status_code: status, body: body}} when status >= 500 -> {:error, Poison.decode!(body)} + {:error, %HTTPoison.Error{reason: reason}} -> {:error, Poison.decode!(reason)} end @@ -26,14 +29,14 @@ defmodule Flowex do # --------------------------------------------------------------------------- # Encode body # --------------------------------------------------------------------------- - @spec _body(String.t() | map) :: String.t + @spec _body(String.t() | map) :: String.t() defp _body(""), do: "" defp _body(body), do: Poison.encode!(body) # --------------------------------------------------------------------------- # Obtine el host de Dialogflow API # --------------------------------------------------------------------------- - @spec _host :: String.t + @spec _host :: String.t() defp _host(), do: Application.get_env(:flowex, :host) # --------------------------------------------------------------------------- @@ -52,7 +55,7 @@ defmodule Flowex do # --------------------------------------------------------------------------- # Obtiene el id y email de un proyecto de dialogflow. # --------------------------------------------------------------------------- - @spec _project_info(String.t) :: map + @spec _project_info(String.t()) :: map defp _project_info(project_id) do :flowex |> Application.get_env(:projects_info) diff --git a/lib/flowex/service/agent.ex b/lib/flowex/service/agent.ex index aaeda5b..1b0dfbd 100644 --- a/lib/flowex/service/agent.ex +++ b/lib/flowex/service/agent.ex @@ -8,7 +8,7 @@ defmodule Flowex.Service.Agent do @doc """ Obtiene el agente al que está asociado el projecto. """ - @spec get(Strint.t) :: tuple + @spec get(Strint.t()) :: tuple def get(project) do Flowex.request(project, :get, "", "") end diff --git a/lib/flowex/service/intents.ex b/lib/flowex/service/intents.ex index 1334462..d693c0d 100644 --- a/lib/flowex/service/intents.ex +++ b/lib/flowex/service/intents.ex @@ -8,13 +8,15 @@ defmodule Flowex.Service.Intents do @doc """ Lista todos los intents de un agente por pageToken. """ - @spec list(String.t, String.t, String.t, String.t | nil, list) :: tuple + @spec list(String.t(), String.t(), String.t(), String.t() | nil, list) :: tuple def list(project, language \\ "es", view \\ "INTENT_VIEW_UNSPECIFIED", token \\ nil, acc \\ []) do case list_by_page(project, language, view, 100, token) do {:ok, %{"intents" => intents, "nextPageToken" => nextPageToken}} -> list(project, language, view, nextPageToken, acc ++ intents) - {:ok, %{"intents" => intents}} -> + + {:ok, %{"intents" => intents}} -> {:ok, acc ++ intents} + {:error, error} -> {:error, error} end @@ -23,11 +25,17 @@ defmodule Flowex.Service.Intents do @doc """ Lista los de intents de un agente por pageToken y definiendo tamaño de pagina. """ - @spec list_by_page(String.t, String.t, String.t, integer, String.t | nil) :: tuple - def list_by_page(project, language \\ "es", view \\ "INTENT_VIEW_UNSPECIFIED", pageSize \\ 100, token \\ nil) do + @spec list_by_page(String.t(), String.t(), String.t(), integer, String.t() | nil) :: tuple + def list_by_page( + project, + language \\ "es", + view \\ "INTENT_VIEW_UNSPECIFIED", + pageSize \\ 100, + token \\ nil + ) do url = "intents?languageCode=#{language}&intentView=#{view}&" <> - "pageSize=#{pageSize}&pageToken=#{token}" + "pageSize=#{pageSize}&pageToken=#{token}" Flowex.request(project, :get, url, "") end @@ -35,7 +43,7 @@ defmodule Flowex.Service.Intents do @doc """ Obtiene un intent buscando por id. """ - @spec get(String.t, String.t, String.t, String.t) :: tuple + @spec get(String.t(), String.t(), String.t(), String.t()) :: tuple def get(project, id, language \\ "es", view \\ "INTENT_VIEW_UNSPECIFIED") do url = "intents/#{id}?languageCode=#{language}&intentView=#{view}" @@ -45,7 +53,7 @@ defmodule Flowex.Service.Intents do @doc """ Crea un intent. """ - @spec create(String.t, map, String.t) :: tuple + @spec create(String.t(), map, String.t()) :: tuple def create(project, body, language \\ "es") do url = "intents?languageCode=#{language}" @@ -55,7 +63,7 @@ defmodule Flowex.Service.Intents do @doc """ Añade un frase de entrenamiento a un intent. """ - @spec add_training_phrase(String.t, String.t, String.t, String.t) :: tuple + @spec add_training_phrase(String.t(), String.t(), String.t(), String.t()) :: tuple def add_training_phrase(project, id, text, language \\ "es") do url = "intents/#{id}?languageCode=#{language}&intentView=INTENT_VIEW_FULL" @@ -71,7 +79,7 @@ defmodule Flowex.Service.Intents do @doc """ Actualiza un intent view full. """ - @spec update(String.t, String.t, map, String.t) :: tuple + @spec update(String.t(), String.t(), map, String.t()) :: tuple def update(project, id, intent, language \\ "es") do url = "intents/#{id}?languageCode=#{language}&intentView=INTENT_VIEW_FULL" @@ -81,14 +89,17 @@ defmodule Flowex.Service.Intents do # --------------------------------------------------------------------------- # Define una frase de entrenamiento. # --------------------------------------------------------------------------- - @spec _set_training_phrase(nil | list, String.t) :: list + @spec _set_training_phrase(nil | list, String.t()) :: list defp _set_training_phrase(nil, text) do - [%{ - "name" => UUID.uuid4(), - "parts" => [%{"text" => text}], - "type" => "EXAMPLE" - }] + [ + %{ + "name" => UUID.uuid4(), + "parts" => [%{"text" => text}], + "type" => "EXAMPLE" + } + ] end + defp _set_training_phrase(training_phrases, text) do [ %{ diff --git a/lib/flowex/service/sessions.ex b/lib/flowex/service/sessions.ex index 13a66b2..d3a43e1 100644 --- a/lib/flowex/service/sessions.ex +++ b/lib/flowex/service/sessions.ex @@ -9,7 +9,7 @@ defmodule Flowex.Service.Sessions do Procesa una consulta en lenguaje natural para detectar un intent con la respuesta apropiada. """ - @spec detect_intent(String.t, String.t, String.t, String.t) :: tuple + @spec detect_intent(String.t(), String.t(), String.t(), String.t()) :: tuple def detect_intent(project, text, session_id, language \\ "es") do body = %{ queryInput: %{ diff --git a/mix.exs b/mix.exs index 2f81366..faf503f 100644 --- a/mix.exs +++ b/mix.exs @@ -3,12 +3,26 @@ defmodule Flowex.Mixfile do def project do [ - app: :flowex, - version: "1.0.0", - elixir: "~> 1.5", - start_permanent: Mix.env == :prod, - deps: deps(), - test_coverage: [tool: ExCoveralls], + app: :flowex, + version: "2.0.0", + elixir: "~> 1.14", + package: package(), + start_permanent: Mix.env() == :prod, + deps: deps(), + aliases: aliases(), + test_coverage: [tool: ExCoveralls], + source_url: "https://github.com/resuelve/flowex", + docs: [ + main: "Flowex" + ] + ] + end + + defp package do + [ + organization: "resuelve", + licenses: [], + links: %{"GitHub" => "https://github.com/resuelve/flowex"} ] end @@ -23,13 +37,20 @@ defmodule Flowex.Mixfile do # Run "mix help deps" to learn about dependencies. defp deps do [ - {:credo, "~> 0.8", only: [:dev, :test]}, - {:elixir_uuid, "~> 1.2" }, - {:excoveralls, "~> 0.10", only: :test}, - {:goth, "~> 0.9.0"}, - {:httpoison, "~> 1.4"}, - {:mock, "~> 0.3.0", only: :test}, - {:poison, "~> 3.1"}, + {:credo, "~> 1.6.7", only: [:dev, :test]}, + {:elixir_uuid, "~> 1.2"}, + {:excoveralls, "~> 0.12", only: :test}, + {:goth, "~> 1.2.0"}, + {:httpoison, "~> 1.8"}, + {:mock, "~> 0.3.0", only: :test}, + {:poison, "~> 3.1"}, + {:ex_doc, "~> 0.27", only: :dev, runtime: false} + ] + end + + defp aliases do + [ + ci: ["format --check-formatted"] ] end end diff --git a/mix.lock b/mix.lock index 30a1ce7..72b1b04 100644 --- a/mix.lock +++ b/mix.lock @@ -1,23 +1,29 @@ %{ - "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"}, - "certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"}, - "credo": {:hex, :credo, "0.9.3", "76fa3e9e497ab282e0cf64b98a624aa11da702854c52c82db1bf24e54ab7c97a", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:poison, ">= 0.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, - "elixir_uuid": {:hex, :elixir_uuid, "1.2.0", "ff26e938f95830b1db152cb6e594d711c10c02c6391236900ddd070a6b01271d", [:mix], [], "hexpm"}, - "excoveralls": {:hex, :excoveralls, "0.10.3", "b090a3fbcb3cfa136f0427d038c92a9051f840953ec11b40ee74d9d4eac04d1e", [:mix], [{:hackney, "~> 1.13", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"}, - "exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"}, - "goth": {:hex, :goth, "0.9.0", "92b30293623d8bd970693ec2aa497651e02542f6fb760d2eb49f30ff08346f59", [:mix], [{:httpoison, "~> 0.11 or ~> 1.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:json_web_token, "~> 0.2.10", [hex: :json_web_token, repo: "hexpm", optional: false]}, {:poison, "~> 2.1 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, - "hackney": {:hex, :hackney, "1.15.1", "9f8f471c844b8ce395f7b6d8398139e26ddca9ebc171a8b91342ee15a19963f4", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, - "httpoison": {:hex, :httpoison, "1.5.0", "71ae9f304bdf7f00e9cd1823f275c955bdfc68282bc5eb5c85c3a9ade865d68e", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, - "idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"}, - "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, - "json_web_token": {:hex, :json_web_token, "0.2.10", "61041d56369422c5e3a770cf7d7bf27224b3c4c12d3a7d79b43a002df766db22", [:mix], [{:poison, "~> 3.1", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, - "jsx": {:hex, :jsx, "2.8.3", "a05252d381885240744d955fbe3cf810504eb2567164824e19303ea59eef62cf", [:mix, :rebar3], [], "hexpm"}, - "meck": {:hex, :meck, "0.8.9", "64c5c0bd8bcca3a180b44196265c8ed7594e16bcc845d0698ec6b4e577f48188", [:rebar3], [], "hexpm"}, - "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"}, - "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm"}, - "mock": {:hex, :mock, "0.3.1", "994f00150f79a0ea50dc9d86134cd9ebd0d177ad60bd04d1e46336cdfdb98ff9", [:mix], [{:meck, "~> 0.8.8", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"}, - "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"}, - "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"}, - "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"}, - "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"}, + "bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"}, + "certifi": {:hex, :certifi, "2.12.0", "2d1cca2ec95f59643862af91f001478c9863c2ac9cb6e2f89780bfd8de987329", [:rebar3], [], "hexpm", "ee68d85df22e554040cdb4be100f33873ac6051387baf6a8f6ce82272340ff1c"}, + "credo": {:hex, :credo, "1.6.7", "323f5734350fd23a456f2688b9430e7d517afb313fbd38671b8a4449798a7854", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "41e110bfb007f7eda7f897c10bf019ceab9a0b269ce79f015d54b0dcf4fc7dd3"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"}, + "elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"}, + "ex_doc": {:hex, :ex_doc, "0.34.2", "13eedf3844ccdce25cfd837b99bea9ad92c4e511233199440488d217c92571e8", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "5ce5f16b41208a50106afed3de6a2ed34f4acfd65715b82a0b84b49d995f95c1"}, + "excoveralls": {:hex, :excoveralls, "0.18.3", "bca47a24d69a3179951f51f1db6d3ed63bca9017f476fe520eb78602d45f7756", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "746f404fcd09d5029f1b211739afb8fb8575d775b21f6a3908e7ce3e640724c6"}, + "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, + "goth": {:hex, :goth, "1.2.0", "92d6d926065a72a7e0da8818cc3a133229b56edf378022c00d9886c4125ce769", [:mix], [{:httpoison, "~> 0.11 or ~> 1.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:joken, "~> 2.0", [hex: :joken, repo: "hexpm", optional: false]}], "hexpm", "4974932ab3b782c99a6fdeb0b968ddd61436ef14de5862bd6bb0227386c63b26"}, + "hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"}, + "httpoison": {:hex, :httpoison, "1.8.2", "9eb9c63ae289296a544842ef816a85d881d4a31f518a0fec089aaa744beae290", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "2bb350d26972e30c96e2ca74a1aaf8293d61d0742ff17f01e0279fef11599921"}, + "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, + "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, + "joken": {:hex, :joken, "2.6.2", "5daaf82259ca603af4f0b065475099ada1b2b849ff140ccd37f4b6828ca6892a", [:mix], [{:jose, "~> 1.11.10", [hex: :jose, repo: "hexpm", optional: false]}], "hexpm", "5134b5b0a6e37494e46dbf9e4dad53808e5e787904b7c73972651b51cce3d72b"}, + "jose": {:hex, :jose, "1.11.10", "a903f5227417bd2a08c8a00a0cbcc458118be84480955e8d251297a425723f83", [:mix, :rebar3], [], "hexpm", "0d6cd36ff8ba174db29148fc112b5842186b68a90ce9fc2b3ec3afe76593e614"}, + "makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"}, + "makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"}, + "meck": {:hex, :meck, "0.9.2", "85ccbab053f1db86c7ca240e9fc718170ee5bda03810a6292b5306bf31bae5f5", [:rebar3], [], "hexpm", "81344f561357dc40a8344afa53767c32669153355b626ea9fcbc8da6b3045826"}, + "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, + "mimerl": {:hex, :mimerl, "1.3.0", "d0cd9fc04b9061f82490f6581e0128379830e78535e017f7780f37fea7545726", [:rebar3], [], "hexpm", "a1e15a50d1887217de95f0b9b0793e32853f7c258a5cd227650889b38839fe9d"}, + "mock": {:hex, :mock, "0.3.8", "7046a306b71db2488ef54395eeb74df0a7f335a7caca4a3d3875d1fc81c884dd", [:mix], [{:meck, "~> 0.9.2", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm", "7fa82364c97617d79bb7d15571193fc0c4fe5afd0c932cef09426b3ee6fe2022"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, + "parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"}, + "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm", "fec8660eb7733ee4117b85f55799fd3833eb769a6df71ccf8903e8dc5447cfce"}, + "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"}, + "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"}, } diff --git a/secrets/.keep b/secrets/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/service/agent_test.exs b/test/service/agent_test.exs index 8e5b081..db9813f 100644 --- a/test/service/agent_test.exs +++ b/test/service/agent_test.exs @@ -23,15 +23,17 @@ defmodule Flowex.Service.AgentTest do { Token, [:passthrough], - [for_scope: fn(_url) -> {:ok, %{token: "0xFAKETOKEN_Q="}} end] + [for_scope: fn _url -> {:ok, %{token: "0xFAKETOKEN_Q="}} end] }, { HTTPoison, [:passthrough], - [request: fn(_method, _url, _params, _headers) -> - body = Poison.encode!(@agent) - {:ok, %HTTPoison.Response{status_code: 200, body: body}} - end] + [ + request: fn _method, _url, _params, _headers -> + body = Poison.encode!(@agent) + {:ok, %HTTPoison.Response{status_code: 200, body: body}} + end + ] } ]) do assert Agent.get("lbot-170198") == {:ok, @agent} diff --git a/test/service/intents_test.exs b/test/service/intents_test.exs index c09fc2c..090cca6 100644 --- a/test/service/intents_test.exs +++ b/test/service/intents_test.exs @@ -7,21 +7,21 @@ defmodule Flowex.Service.IntentsTest do alias Goth.Token @intents %{ - "intents" => [ - %{ - "displayName" => "Acción (Despedida)", - "messages" => [%{"text" => %{"text" => ["Bye", "Nos vemos"]}}], - "name" => "projects/lbot-170189/agent/intents/4cff39af-ba13-4a62-ba6f-8a79f4f5b324", - "priority" => 500000 - } - ] + "intents" => [ + %{ + "displayName" => "Acción (Despedida)", + "messages" => [%{"text" => %{"text" => ["Bye", "Nos vemos"]}}], + "name" => "projects/lbot-170189/agent/intents/4cff39af-ba13-4a62-ba6f-8a79f4f5b324", + "priority" => 500_000 + } + ] } @intent %{ "displayName" => "Acción (Despedida)", "messages" => [%{"text" => %{"text" => ["Bye", "Nos vemos"]}}], "name" => "projects/lbot-170189/agent/intents/4cff39af-ba13-4a62-ba6f-8a79f4f5b324", - "priority" => 500000 + "priority" => 500_000 } @intent_view_full %{ @@ -30,7 +30,9 @@ defmodule Flowex.Service.IntentsTest do %{ "text" => %{ "text" => [ - "Aquí no más", "Esperando a que preguntes algo", "Trabajando ¿y tú?" + "Aquí no más", + "Esperando a que preguntes algo", + "Trabajando ¿y tú?" ] } } @@ -56,11 +58,11 @@ defmodule Flowex.Service.IntentsTest do } @invalid_intent %{ - "error" => %{ - "code" => 400, - "message" => "Intent with the display_name 'test' already exists.", - "status" => "FAILED_PRECONDITION" - } + "error" => %{ + "code" => 400, + "message" => "Intent with the display_name 'test' already exists.", + "status" => "FAILED_PRECONDITION" + } } test "list list all intents" do @@ -68,15 +70,17 @@ defmodule Flowex.Service.IntentsTest do { Token, [:passthrough], - [for_scope: fn(_url) -> {:ok, %{token: "0xFAKETOKEN_Q="}} end] + [for_scope: fn _url -> {:ok, %{token: "0xFAKETOKEN_Q="}} end] }, { HTTPoison, [:passthrough], - [request: fn(_method, _url, _params, _headers) -> - body = Poison.encode!(@intents) - {:ok, %HTTPoison.Response{status_code: 200, body: body}} - end] + [ + request: fn _method, _url, _params, _headers -> + body = Poison.encode!(@intents) + {:ok, %HTTPoison.Response{status_code: 200, body: body}} + end + ] } ]) do assert Intents.list("lbot-170198") == {:ok, @intents["intents"]} @@ -88,15 +92,17 @@ defmodule Flowex.Service.IntentsTest do { Token, [:passthrough], - [for_scope: fn(_url) -> {:ok, %{token: "0xFAKETOKEN_Q="}} end] + [for_scope: fn _url -> {:ok, %{token: "0xFAKETOKEN_Q="}} end] }, { HTTPoison, [:passthrough], - [request: fn(_method, _url, _params, _headers) -> - body = Poison.encode!(@intent) - {:ok, %HTTPoison.Response{status_code: 200, body: body}} - end] + [ + request: fn _method, _url, _params, _headers -> + body = Poison.encode!(@intent) + {:ok, %HTTPoison.Response{status_code: 200, body: body}} + end + ] } ]) do assert Intents.get("lbot-170198", "5eec5344-8a09-40ba-8f46-1d2ed3f7b0df") == {:ok, @intent} @@ -108,20 +114,25 @@ defmodule Flowex.Service.IntentsTest do { Token, [:passthrough], - [for_scope: fn(_url) -> {:ok, %{token: "0xFAKETOKEN_Q="}} end] + [for_scope: fn _url -> {:ok, %{token: "0xFAKETOKEN_Q="}} end] }, { HTTPoison, [:passthrough], - [request: fn(_method, _url, _params, _headers) -> - body = - @create_attrs - |> Map.put(:name, "projects/lbot-170198/agent/intents/05f93e97-194d-469b-8721-70b5b6df9c82") - |> Map.put(:priority, 500000) - |> Poison.encode!() - - {:ok, %HTTPoison.Response{status_code: 200, body: body}} - end] + [ + request: fn _method, _url, _params, _headers -> + body = + @create_attrs + |> Map.put( + :name, + "projects/lbot-170198/agent/intents/05f93e97-194d-469b-8721-70b5b6df9c82" + ) + |> Map.put(:priority, 500_000) + |> Poison.encode!() + + {:ok, %HTTPoison.Response{status_code: 200, body: body}} + end + ] } ]) do assert {:ok, intent} = Intents.create("lbot-170198", %{displayName: "test"}) @@ -135,15 +146,17 @@ defmodule Flowex.Service.IntentsTest do { Token, [:passthrough], - [for_scope: fn(_url) -> {:ok, %{token: "0xFAKETOKEN_Q="}} end] + [for_scope: fn _url -> {:ok, %{token: "0xFAKETOKEN_Q="}} end] }, { HTTPoison, [:passthrough], - [request: fn(_method, _url, _params, _headers) -> - body = Poison.encode!(@invalid_intent) - {:ok, %HTTPoison.Response{status_code: 400, body: body}} - end] + [ + request: fn _method, _url, _params, _headers -> + body = Poison.encode!(@invalid_intent) + {:ok, %HTTPoison.Response{status_code: 400, body: body}} + end + ] } ]) do assert {:error, errors} = Intents.create("lbot-170198", %{displayName: "test"}) @@ -157,21 +170,24 @@ defmodule Flowex.Service.IntentsTest do { Token, [:passthrough], - [for_scope: fn(_url) -> {:ok, %{token: "0xFAKETOKEN_Q="}} end] + [for_scope: fn _url -> {:ok, %{token: "0xFAKETOKEN_Q="}} end] }, { HTTPoison, [:passthrough], - [request: fn(_method, _url, _params, _headers) -> - body = Poison.encode!(@intent_view_full) - {:ok, %HTTPoison.Response{status_code: 200, body: body}} - end] + [ + request: fn _method, _url, _params, _headers -> + body = Poison.encode!(@intent_view_full) + {:ok, %HTTPoison.Response{status_code: 200, body: body}} + end + ] } ]) do - assert Intents.update("lbot-170198", "5eec5344-8a09-40ba-8f46-1d2ed3f7b0df", - @intent_view_full) == {:ok, @intent_view_full} + assert Intents.update( + "lbot-170198", + "5eec5344-8a09-40ba-8f46-1d2ed3f7b0df", + @intent_view_full + ) == {:ok, @intent_view_full} end end - - end diff --git a/test/service/sessions_test.exs b/test/service/sessions_test.exs index 2a0b073..46b3365 100644 --- a/test/service/sessions_test.exs +++ b/test/service/sessions_test.exs @@ -30,19 +30,21 @@ defmodule Flowex.Service.SessionsTest do { Token, [:passthrough], - [for_scope: fn(_url) -> {:ok, %{token: "0xFAKETOKEN_Q="}} end] + [for_scope: fn _url -> {:ok, %{token: "0xFAKETOKEN_Q="}} end] }, { HTTPoison, [:passthrough], - [request: fn(_method, _url, _params, _headers) -> - body = Poison.encode!(@query) - {:ok, %HTTPoison.Response{status_code: 200, body: body}} - end] + [ + request: fn _method, _url, _params, _headers -> + body = Poison.encode!(@query) + {:ok, %HTTPoison.Response{status_code: 200, body: body}} + end + ] } ]) do - assert Sessions.detect_intent("lbot-170198", "Hola", "1e8118272e2f69ea6ec98acbb71ab959") == {:ok, @query} + assert Sessions.detect_intent("lbot-170198", "Hola", "1e8118272e2f69ea6ec98acbb71ab959") == + {:ok, @query} end end - end