deadCL Chat-bot
(Arnold)
View tutorials overview
Introduction
While we have a simple chat-bot template available Parcel Arnold was engineered specifically for chat or short-interaction communication therefore please consider this tutorial over it's DRM alternative.The Library & Conversation used are linked below, for both comparison and ease of execution.
Everything shown in blue must be substituted with your own values.
This tutorial will not deal with the initial establishment of DeadLetter or your web server/web presence.
What you'll learn
- | How to use setup Arnold (Parcel) |
---|---|
- | How to use Parcel for inputs & outputs for conversing using Arnold |
- | How to utilise recall in Arnold |
What you'll need
- | A Github: in this example we're using Github (as host) but you could substitute any service or your own VPS |
---|---|
- | html POST endpoint you'll somewhere to receive output from the 'database' |
- | Author Key: it goes without saying you'll need an Author Key - ideally setup with a Parcel endpoint |
Step One - Setup, define & set parameters
Before we go any further we need to create & setup how our Arnold & remote endpoints. This lays the foundation for how we 'communicate' with deadCL via Parcel.The Library below shows how we're structuring our endpoints.
RECEIVE-WEBHOOK; PARCEL- A jSCW3t SEND-WEBHOOK; PARCEL- A api.domain.com/chat-bot MESSAGE; PARCEL- A $_user A $_message
Receiving Messages
The first step is setting our input (you'll need to an exisiting Parcel endpoint configured for Arnold)In this example we've set our input as jSCW3t you'll need to ensure your Arnold endpoint is configured with this value.
You can learn how here.
RECEIVE-WEBHOOK; PARCEL- A jSCW3t
Sending Messages
Next we need to define our remote endpoint (the URI to send responses to).As a placeholder we've used api.domain.com/chat-bot you'll need to change this to where deadCL is POST responses
You can learn how here.
SEND-WEBHOOK; PARCEL- A api.domain.com/chat-bot
Handling parameters
Arnold is designed exclusively for messaging, therefore you must always include 'user' & 'message' when performing a POST requestHere we've setup both parameters to be actionable with one KC using substitutions to handle values.
MESSAGE; PARCEL- A $_user A $_message
Step Two - MBS Definitions
Let's move onto setting our MBS definitions, conversational elements are heavily reliant on both dictionary meaning & basic language principles provided by Offical DeadLetter Libraries - however sometimes it's safer to explicitly define a words meaning when required for MBS.To begin with lets set our MBS definitions.
INTERPRET; {to describe the meaning of something; examine in order to explain} {DEFINE THE CONTEXT OF WORDS] CALCULATE; {to judge the INTERPRETATION by using the information that you already have} RESPONSE; {an answer or reaction} DEFINE; {meaning of SOMETHING, WORDS describe the meaning and exact limits of something} MEANING; {meaning of something is what it expresses or represents} WORD; {a single unit of language that has meaning and can be spoken or written} SORT; {the act of separating things and putting them in a particular order}
Definitions - Interpret
While we could rely solely on the encoded meanings of the Oxford Dictionary (UK) it's safer to ensure the meaning used it as we've interpreted or modified.For example we've amended the meaning of INTERPRET to;
"to describe the meaning of something; examine in order to explain &;
DEFINE THE CONTEXT OF WORDS"
By doing this the process of Interpreting inbound messages is clearer, with little need to update or amend.
INTERPRET; {to describe the meaning of something; examine in order to explain} {DEFINE THE CONTEXT OF WORDS]
Step Three - Handling words
Now things get interesting, for responses to be comprehendible we need to arrange & interpret the input - in this case 'words'. The Code below is a more refined version of our Offical Word Interpretation Libraries designed to be used with & without an Array.Below is the Library section which handles this task.
MESSAGE -- RECEIVE-WEBHOOK; VAL_ C#{ $ } $ = W* W_0; 'W' W_1; 'WW' W_3; 'WWW' W_4; 'WWWW' W_5; 'WWWWW' WS_0; { C_var(W+WW) } WS_1; { C_var(WWW+WWWW) } WS_2; { C_var(WS_0+WS_1) } STATE; W_0 /recall -- Oxford University Press, HOLD_STATE W_1 /recall -- Oxford University Press, HOLD_STATE W_2 /recall -- Oxford University Press, HOLD_STATE W_3 /recall -- Oxford University Press, HOLD_STATE W_4 /recall -- Oxford University Press, HOLD_STATE W_5 /recall -- Oxford University Press, HOLD_STATE { C [ WS_0 -- INTERPRET = WI_0 WS_1 -- INTERPRET = WI_1 WS_2 -- INTERPRET = WI_2 ] = INTP } inpr_{ 'INTP' } = X C_POST C_inpr('X')
Labelling Words
Before we can perform an interpretation deadCL must be informed of where & how to treat the input.In-order to do this we'll tokenise the input as $, before transforming the single value into multiple values under the moniker W
Each 'section' is subsequently given a new value as follows W_0, W_1, W_2, W_3, W_4, W_5
RECEIVE-WEBHOOK; VAL_ C#{ $ } $ = W* W_0; 'W' W_1; 'WW' W_3; 'WWW' W_4; 'WWWW' W_5; 'WWWWW'
Grouping 'words' for interpretation
Next we need to create a series of groups each is designed to perform 'micro' interpretations, this enables us to block inbound messages into three interpreted sections.You'll notice we're creating data-sets that progressively more through each section, once again reducing the number from five to one values.
WS_0; { C_var(W+WW) } WS_1; { C_var(WWW+WWWW) } WS_2; { C_var(WS_0+WS_1) }
Interpreting Values
Here we recall the definition(s) of each section using the Oxford Dictionary meaning & hold the value using;W_0 /recall -- Oxford University Press, HOLD_STATE
Before performing a further recursive interpretation to reach our 'final' object values. Which are;
WI_0 WI_1 WI_2
You'll notice here we're mixing MBS & Fixed Syntax in-order to simplify our interpretation command(s).
STATE; W_0 /recall -- Oxford University Press, HOLD_STATE W_1 /recall -- Oxford University Press, HOLD_STATE W_2 /recall -- Oxford University Press, HOLD_STATE W_3 /recall -- Oxford University Press, HOLD_STATE W_4 /recall -- Oxford University Press, HOLD_STATE W_5 /recall -- Oxford University Press, HOLD_STATE { C [ WS_0 -- INTERPRET = WI_0 WS_1 -- INTERPRET = WI_1 WS_2 -- INTERPRET = WI_2 ] = INTP }
Final Checks & Posting
You'll notice rather than 'POSTING' WI_2 exclusively we've created an interpretable object string. and combined the values of all three final values of INTPWe've done this to avoid loss of 'word' or gobbledygook outputs, however you could remove this 'safety-net' if you wish by substituting inpr_{ 'INTP' } with WI_2
inpr_{ 'INTP' } = X C_POST C_inpr('X')
Step Four - The Conversation
Lets move onto the Conversation. Our Conversation performs three functions1. | Performing an 'does it make sense' test |
---|---|
2. | Structuring a fluid response to 'X' |
3. | Posting a JSON request to your remote endpoint |
dld.keyset('NAME_YOURNAME') *Catch-all - libs REACT; {reply to, respond} 'X', INTERPRET = 'M' RESPOND; { calculate, RESPONSE 'M' = $_message } User; $_user ^PAUSE POST; ON, REACT PARCEL- A 'MESSAGE' -- SEND-WEBHOOK *END
Adding Libraries
If you don't want to use a local Libraries then the best option (or the very least, safest for testing) is to use the Offical DeadLetter Libraries by adding them all.Don't forget to check your Domain is set correctly in your Author Key.
*Catch-all - libs
Checking interpretation
The first step we'll take is a basic check, that 'X' makes sense before rewriting the object value as; 'M'The inclusion of {reply to, respond} aids our MBS command INTERPRET to correctly 'check' the value.
REACT;
{reply to, respond}
'X', INTERPRET = 'M'
Forming a response
To create a fluid response we're the following MBSCALCULATE | Here calculate is being employed to initiate the creation of our response |
---|---|
RESPONSE | Is informing upon the relationship to 'M' |
As we're simply posting to a URI with no user-classes we'll define $_user as nothing, result in a NILL value being posted.
RESPOND;
{ calculate, RESPONSE 'M' = $_message }
User;
$_user
^PAUSE
Making the Post request
Here we're just posting the values assigned to $_message &$_user as defined in our Library to the endpoint with the value SEND-WEBHOOK
POST; ON, REACT PARCEL- A 'MESSAGE' -- SEND-WEBHOOK
You're Done!
By now you should have a (very) basic understanding of using Arnold to create a chat-bot with DeadLetter (deadCL)This code can easily be modified to create a multi-user chat application, to reply to emails or social-media bot.