Skip to content

Commit 38e2da3

Browse files
committed
feat: poc polymorphism for journey
1 parent 83d4ab5 commit 38e2da3

8 files changed

+102
-2
lines changed

lib/block.ex

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defprotocol BlockFunction do
2+
def init(state)
3+
def run(state)
4+
end
5+
6+
defmodule Block do
7+
@callback init(state :: term) :: {:ok, new_state :: term} | {:error, reason :: String.t()}
8+
@callback run(state :: term) :: {:ok, result :: term} | {:error, reason :: String.t()}
9+
end

lib/conversation.ex

Whitespace-only changes.

lib/if_block.ex

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
defmodule IfBlock do
2+
defstruct state: nil, validator: nil
3+
@behaviour Block
4+
5+
def new(arg) do
6+
%IfBlock{state: arg}
7+
end
8+
9+
def init(state) do
10+
{:ok, state}
11+
end
12+
13+
def run(state) do
14+
IO.puts("if block")
15+
IO.inspect(state)
16+
{:ok, state}
17+
end
18+
19+
defimpl BlockFunction do
20+
def init(state) do
21+
IO.puts("initing")
22+
end
23+
24+
def run(state) do
25+
IO.puts("state")
26+
IO.inspect(state)
27+
end
28+
end
29+
end

lib/journey.ex

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
defmodule Journey do
2+
@moduledoc """
3+
vertices are just atoms
4+
how are they linked to a block(?)
5+
edges are links between atoms
6+
"""
7+
defstruct graph: Graph.new()
8+
9+
def new() do
10+
%Journey{}
11+
end
12+
13+
def insert_block() do
14+
end
15+
16+
def insert_block(from, to) do
17+
end
18+
19+
@doc """
20+
Returns the block id where the user's conversation is at.
21+
"""
22+
def where_is(user) do
23+
end
24+
25+
defdelegate run(block), to: BlockFunction
26+
end

lib/kabootar.ex

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
defmodule Kabootar do
22
@moduledoc """
3-
Documentation for `Kabootar`.
3+
Build human-in-the-loop conversation bot.
4+
5+
Kabootar helps you model a conversation between users and the system. There are two types of conversations - pre-determined and free-flowing. In a free flowing conversation users and the bot can talk to each other in any order. In a pre-determined conversation who says what at each instant is modelled using a rule based system.
6+
7+
For a pre-determined conversation, message events occur in a fixed order. The message event is used to determine the next steps in a conversation.
8+
9+
Define Conversations using easy to configure functions called Blocks.
10+
11+
Conversation -> Journey -> Blocks
12+
Every event in a conversation belongs to a journey
13+
14+
Conversation is a graph. It stores the state and using the event, you can determine the next node.
15+
16+
What the human in the loop means is that a user can move the user from one part of the conversation to another, override the output of an automated system without disrupting the user experience for the user.
17+
18+
## Usage
19+
Journey.create()
20+
Journey.add_block()
21+
Journey.add_blocks()
22+
Conversation.start(user, journey)
23+
Conversation.move(user, journey)
24+
Journey.run(if_block)
425
"""
526

627
@doc """

lib/message_block.ex

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
defmodule MessageBlock do
2+
@behaviour Block
3+
4+
def init(state) do
5+
{:ok, state}
6+
end
7+
8+
def run(state) do
9+
IO.inspect("message block")
10+
IO.inspect(state)
11+
{:ok, state}
12+
end
13+
end

mix.exs

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ defmodule Kabootar.MixProject do
4646
defp deps do
4747
[
4848
{:ex_doc, "~> 0.34.2", only: :dev, runtime: false},
49-
{:versioce, "~> 2.0.0"}
49+
{:versioce, "~> 2.0.0"},
50+
{:libgraph, "~> 0.16.0"}
5051
]
5152
end
5253
end

mix.lock

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
%{
22
"earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"},
33
"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"},
4+
"libgraph": {:hex, :libgraph, "0.16.0", "3936f3eca6ef826e08880230f806bfea13193e49bf153f93edcf0239d4fd1d07", [:mix], [], "hexpm", "41ca92240e8a4138c30a7e06466acc709b0cbb795c643e9e17174a178982d6bf"},
45
"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"},
56
"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"},
67
"makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"},

0 commit comments

Comments
 (0)