I
I
Igor2020-08-05 05:11:20
Bots
Igor, 2020-08-05 05:11:20

Changing the bot's dialogue as the play progresses?

Colleagues, welcome!

Recently I was impatient to write a bot.
It worked out pretty well for me.

I decided not to stop there and file an adaptive dialogue.

Yes, I know, there is the most powerful Microsoft Bot Framework , everything is there and there is nothing.
But it doesn't even have what I want.

More precisely, I don’t like writing bots at all and this is not my idea.

In general, how to make an adaptive dialog?
The problem is that there is a certain chat.
5f2a128c9f778901961494.png
This chat is able to communicate through the channel of the bot.
Yes, it worked out well.

But how can we make sure that from the side of our system we can prepare scripts and change the behavior of the bot.

I'll give you an example.
How does a classic bot work?

main.use(async ({message, session, di}: BotContextInterface, next) => {
  const redis: Tedis = di.get('redis');
  const tgl = main.adapter.getApi()
  const msg = new MessageTelegram(message.getRawData())

  // Если нет маркера доступа, предлагаем пройти авторизацию или регистрацию.
  if (await redis.exists(message.getSessionKey('token_'))) {
    session.setState({
      token: await redis.hgetall(message.getSessionKey('token_'))
    })
  } else {
    if (session.isNew) {
      const m = []
      m.push('Привет, я о тебе ничего не знаю.')

      // Gender
      switch (getGender({first: msg.getUser().first_name, last: msg.getUser().last_name})) {

        case 'male': {
          m.push('Ты уже бывал здесь?')
          break
        }

        case 'female': {
          m.push('Ты уже бывала здесь?')
          break
        }

        default: {
          m.push('Ты уже бывал здесь?')
        }
      }

      await session.send(new Message({
        user_id: message.getUserId(),
        text: m.join('\n')
      }))
      // setTimeout(async () => {
      //   const m = []
      //   m.push('Что бы продолжить нажми /start')
      //   await session.send(new Message({
      //     user_id: message.getUserId(),
      //     text: m.join('\n')
      //   }))
      // }, 3000)
    }
  }

  next()
});

All this is boring.

But there is an interesting part of the code in the chat.
if (typeof sse.onMessage !== 'function') {
        sse.onMessage = function (eventData: EventDataInterface) {
          if (eventData.type === 'json') {
            main.emitter.emit('chat-broker', {message, session, di, data: JSON.parse(eventData.data)})
          }
        }
      }

Which translates all the bot's dialogues into the chat, which I have shown in the screenshot.

What can you think of to slip through this hole different scenarios of communication?
Scenarios are prepared in advance.

Sample script
===============
User: Hello
Bot: Hello
Bot: Enter number 1
User: 1
End of script.

I don’t even know what to think, I’m doing such crap.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question