Answer the question
In order to leave comments, you need to log in
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.
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()
});
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)})
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question