eFishery / Nemo
Programming Languages
Labels
Projects that are alternatives of or similar to Nemo
NeMo Whataspp ChatBot
A simple question answer like chatbot to simplify you data input.
Showcase
NeMo as the WhatsApp Shop Online Assistant
How to run
to run you need to have enviroment variable as in .env.example
, rename it to .env
, by default you need to create coral
dir or you can specify by env var CORAL_DIR
. The coral
dir is for the bot configuration, so create a coral
directory and put all the coral file in this folder, also you need the WhatsApp session file in order to connect to the current phone
Use this tools to generate the whatsapp session file k1m0ch1/WhatsappLogin, you can download the latest binary file from the latest release
and run with command ./WhatsappLogin -p 08123123123
and scan the QR
or
run with docker
docker run --rm -v sessions:/go/src/github.com/k1m0ch1/WhatsappLogin/sessions k1m0ch1/whatsapplogin:latest -p 08123123123
after you have file 08123123123.gob
and coral
directory with basic.yml
inside, run the NeMo with this command
./NeMo 08123123123
this will find the file 08123123123.gob
in the SESSION_DIR
environment variable by default this will goes to current directory running file
Run With Docker
you must prepare the coral
directory include with yaml file and Whatsapp file session, after that mount volume in docker with example command like this
docker run \
--name NeMo -v $(pwd)/coral:/app/coral \
-v $(pwd)/.sessions/08123123123.gob:/app/08123123123.gob \
k1m0ch1/nemo 08123123123
Understand Basic Coral Configuration
Coral as in the house of the clown fish, is the configuration of the bot in order to specific give the operation to NeMo, you can see the example from the basic.yml
or example.yml
file
Author
Specifically to define the author of the configuration
author:
name: name
phone: "08123123123"
email: [email protected]
Default Greeting
This will be triggered when users chat any text to NeMo and start to send message
and expected by the variable expected_users
default_greeting:
message: "to start talk with me type\n\n*!start*"
**note: default greeting will never sent to group
Commands
just remember if you want to record or in run process after triggering the commands, but the True
value for record
and run_process
commands:
prefix: "!"
command: "start"
run_process: True
message: "Let's start how cool you are"
Message Format Parser
you can use the message with the URL POST with format {{URL}}
with POST method
the NeMo will handle this body Response
{
"message": "response",
"images": [
{
"URL": "link to image",
"caption": "caption"
}
]
}
The message
key will sent a normal response
The images
key will stored all the image information, and will send the image regarding the length of the array
The URL
key will parse the image from internet and sent this with a new response along side with the caption
also you can get the indexing of the parameter when user using the command and add some argument, for example user type this command
!start hello world
this will trigger this command to having a argument, and whenever the message include the message indexing like {{1}}
or {{2}}
this will return the argument index, if the message with the format like this everyone {{1}}, I love the {{2}}
this will return message everyone hello, I love the world
if the argument is using number you can use function sum(argumentindex,argumentindex,...)
to calculate between number, for example the message following format we have {{1}} {{2}} {{3}} and sum of {{1}} and {{3}} is {{sum(1,3)}}
with user type the command like this !start 3 2 1
this will return we have 3 2 1 and sum of 3 and 1 is 4
for example if you type !start hello
in the chat, the NeMo will sent the body like in the Webhook part and the hello
will be inserted in the question part.
Process
This configuration define the question after commands triggered, for a
in order to use validation rule image
, you need to specify AWS S3
configuration in .env
file
process:
record: True
log: False
timeout: 300
exit_command:
prefix: "!"
command: stop
message: "alright I'll stop asking"
end_message: "Hey its done, thank you"
questions:
- question:
slug: first
asking: please take a pic your beautiful face
validation:
rule: image
message: "must a pic dude!"
- question:
slug: second
asking: tell me some random number
validation:
rule: ^[0-9]*$
message: you can't read that ? I ask you to write some number
if you set the key record
to True
you need to add the Webhook
part
when you set the log
key into True, you need to add log
parent key
Webhook
In order to save all the input data, you can rely on webhook that built in this ChatBot
webhook:
service: WEBHOOK
url: https://url.com/webhook
the data will be sent with POST
method to url
key with body JSON
like this
{
"phone_number": "628123123123",
"current_process": "basic",
"current_question_slug": 1,
"process_status": "DONE",
"data": [
{
"slug": "first",
"question": "please take a pic your beautiful face",
"answer": "https=//public-tools.s3.ap-southeast-1.amazonaws.com/fresh/nemo/645C4CC4141DB97B2A29BBE33725B1BE.jpeg",
"created": "2020-09-25T13:54:56+07:00"
},
{
"slug": "second",
"question": "tell me some random number",
"answer": "1200",
"created": "2020-09-25T13:55:17+07:00"
}
],
"sent": "",
"sent_to": "",
"created": "2020-09-25T13:54:19+07:00",
"expired": "2020-09-25T13:59:19+07:00",
"finished": "2020-09-25T13:55:17+07:00"
}
Log
In order to log every user input when the process start, you can rely on log that built in this ChatBot
webhook:
service: WEBHOOK
url: https://url.com/webhook
the data will be sent with POST
method to url
key with body JSON
like above on webhook part
Expected Users
is a list of a phone number that expected by ChatBot, technically a whitelist that chatbot will hear, currenlt I made this for a specific phone number, because I'm not making this for "any" users, currently I want to made that, but I need more validation to implement that
expected_users:
- 628123123123
- 628321321312
you can set the expected_users
to any
so this will targeted the any
user for command
and default_greeting
but the schedules
will be disabled due to any
users.
to activate bot in group you can just simply add the phonenumber-groupid
expected_users:
- any
in order for NeMo can run within WhatsApp, you need the whatsapp file session
Generate WhatsApp File Session
Use this tools to generate the whatsapp session file k1m0ch1/WhatsappLogin
you can download the latest binary file from the latest release
and run with command ./WhatsappLogin -p 08123123123
and scan the QR
or
run with docker
docker run --rm -v sessions:/go/src/github.com/k1m0ch1/WhatsappLogin/sessions k1m0ch1/whatsapplogin:latest -p 08123123123
Development Environment
How to run
go run . 08123123123
this will find the file 08123123123.session
in the SESSION_DIR
environment variable by default this will goes to current directory running file
To Do
[] need to validate if the ChatBot already sent the message, so he will not sent a duplicate message
[] weird file session JSON error parsing, weirdly added the "":"}
string in the end
[] build for ANY expected users, along with the builder
[] if error logging in, try to re-login
[] YAM file can be .yaml
or .yml
, currently only yml
is validated
Done List
[] Multi Schedule is not
[] Multi file yml with some with no greeting or no schedule or no commands
[] must test all the builder work well
[] ~ada orang yang nyangkut gara gara status NEXT nya diem, bisanya nge break pas ada ~
[] semua bentuk dokumen harus di kasih handler
[] ada orang yg kirim gambar langsung tanpa command atau session apapun, langsung ngebreak soalnya dia mencoba coral yg tidak exist
[] kirim gambar langsung modar
[] ga ada sesinya langsung modar, masalah di image handler