Skip to content

A Telegram chatbot using NLP and MongoDb with a Spanish corpus.

License

Notifications You must be signed in to change notification settings

neodmy/telegram_bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram bot

A Telegram conversational chatbot using node-nlp, Telegraf and MongoDb with a Spanish corpus.

Table of contents

  1. Overview
  2. Configuration
  3. Dependencies
  4. Dev dependencies

Overview

When the app starts up, it will load the corpus from corpus-es.json (mind that the provided corpus is in Spanish; node-nlp is also configured to work with Spanish as language). It will trigger the node-nlp training algorithm (notice pipelines.md).

To provide an authorization mechanism, this app will check that the startPayload value matches the one provided in the env var UNIQUE_CODE. This means the bot will interact with the user only if he/she initiated the conversation with the bot though a link with such parameter:

https://telegram.me/<you_bot_username>?start=<UNIQUE_CODE>

To validate further conversations, the app will store the content of the ctx.update.message.chat object provided by the Telegraf API:

{
  "id": 45930123,
  "first_name": "John",
  "last_name": "Doe",
  "type": "private"
}

On every message, the app will store information that can be used for further training:

{
  "id": 45930123,
  "message": "what's your name",
  "firstName": "John",
  "lastName": "Doe",
  "utterance": "what's your name",
  "intent": "agent.name",
  "score": 1,
  "answer": "I don't have one yet"
}

Configuration

To run this app, you will need to provide the following env vars

BOT_TOKEN=token generated by BotFather
UNIQUE_CODE=randomly generate code to check on /start and authorize chat id
MONGODB_CONNECTION_STRING=connection string of your mongo instace
DATABASE_NAME=name of the database to store the results of the prediction

Optionally, you may use

WELCOME_MESSAGE=message the bot will send on /start
UNATHORIZE_MESSAGE=message the bot will send if startPayload does not match UNIQUE_CODE
MIN_SCORE=minimum value for the prediction score of node-nlp

Dependencies

"@nlpjs/basic": "^4.23.4",
"@nlpjs/lang-es": "^4.23.4",
"mongodb": "^4.4.1",
"telegraf": "^4.7.0"

Dev dependencies

"dotenv": "^16.0.0",
"eslint": "^8.12.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.25.4",
"nodemon": "^2.0.15"

About

A Telegram chatbot using NLP and MongoDb with a Spanish corpus.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published