Introduction to Chatbots

12.6.4.1 define the types of chatbots;  
12.6.4.2 argue for the use of chatbots; 
12.6.4.3 explain the meaning of the API.

Introduction to Chatbots

A chatbot is a computer program that simulates a human conversation that uses artificial intelligence (AI) and natural language processing (NLP) to understand customer questions and automate their responses.

The advantage of chatbots is the ability to answer the user's question instantly.

A simple chatbot solves problems by parsing user input and scanning its database for articles related to specific words and phrases. In other words, it works like a document search engine based on key queries.

Classification of chatbots

By way of interaction:

  • Text bots. They analyze the text sent by the client and highlight keywords in it. Their answer to the question asked will be built in accordance with the information received from the user. Due to the large variability of response to a request, such chatbots create the illusion of real communication for users.
  • Voice bots. These virtual assistants are able to recognize human speech and identify keywords in it. They respond to the request with a voice that is generated through the use of neural network models. At the same time, the illusion of live communication is complete, and few people are able to understand that they are conducting a dialogue not with a real person, but with a robot.

By area of application:

  • In messengers. These are chatbots in Telegram, Viber, WhatsApp, and other messaging services.
  • On websites. In this case, the user sees a separate dialog box in which he can ask the bot questions of interest.
  • By phone. A voice chatbot is able to answer customer calls and provide assistance. Especially often such virtual assistants are used by banks. When a call is received, the chatbot will analyze the client's question and issue an answer in accordance with the request. If the user's problem is not common and cannot be solved with the help of a robot, then you will be switched to a real employee. Bots can not only receive calls but also make them. Often, robots call us to tell us about a promotion or to remind us of a planned event.
  • In applications. Robots help with complex applications and explain their functions to users. However, some chatbots have their own application. For example, Alice from Yandex.
  • in a separate device. This may be a separate speaker or other technique for using a voice assistant.

Popular platforms for using chatbots:

  • Telegram
  • Viber
  • VKontakte

How to create a chatbot?

You can create a bot yourself using programming skills.

To create chatbots, we use Python and API.

API (Application programming interface) is a contract that a program provides.

In other words, they are ready-made tools for implementing an interface between your program and the application that provides the API.

API features:

  • Provides access to ready-made tools. For example, the functions of the TensorFlow machine learning library - help to quickly create a neural network without wasting time developing tools from scratch.
  • Increases security. The API allows you to move functionality that must be protected into a separate application. This reduces the possibility of incorrect use of these functions by other programs.
  • Links different systems. If you need to connect a payment system or authorization through social networks to the site, you cannot do without the API.
  • Reduces development cost. It is often cheaper to use a paid API than to create functionality from scratch.

Additionally about API.

Step I

  1. Get the API of the application
  2. Open in Telegram bot @BotFather
  3. Input command /newbot
  4. Create a name for your chatbot
  5. Copy token API

Step II

  1. Install library pyTelegramBotAPI (Win+R --> cmd --> pip install pyTelegramBotAPI)
  2. Open Wing and write code for echo-chatbot

import telebot

API_TOKEN = "put_your_API"

# create a bot object to connect to the chatbot
bot = telebot.TeleBot(API_TOKEN)

#start command handler
@bot.message_handler(content_types=['text'])
def echo(message):
    #output echo message of bot
    bot.send_message(message.chat.id, text=f"{message.text}")

#infinity work of chatbot
bot.polling(none_stop=True)

Step III

  1. Start your program
  2. Start your chatbot on Telegram

Create a simple chatbot Telegram.

 


Questions:

1. What is a chatbot?

2. Name the type of chatbot.

3. Give three examples of applying chatbots.

4. Name popular applications for the creation of chatbots

4. How chatbot process the inputs of user?


Exercises:


Tasks:

Task 1 "Echo bot"

Create an echo bot that repeats the user's entered text.

Task 2 "Polite echo bot"

Modify the bot from the previous task so that it responds with the message: "I received the message <original message>."

Task 3 "Bot is a foreigner"

Modify the bot from the previous task so that it responds with the message: "Hello!" if the user entered "Hello" in any case, otherwise print "I don't understand you".

 

Категория: Programming languages | Добавил: bzfar77 (25.03.2023)
Просмотров: 4362 | Теги: API, Chatbot, Python, telegram | Рейтинг: 5.0/2
Всего комментариев: 0
avatar