L
L
leonardo_malbro2021-06-01 17:35:47
In contact with
leonardo_malbro, 2021-06-01 17:35:47

How to make the bot react to @ or *?

How to make the bot respond to @ or *?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BornTo FreeFall, 2021-06-01
@BornToFreeFall

An example is given using "vk-io". The implementation was available somewhere on this site, found, tested. Works.

const GROUP_ID = SOME_GROUP_ID;

const mentionPattern = new RegExp(
    String.raw`^(?:\[-${GROUP_ID}\|[^\]]+\])(?:[\s.,\'\"!?\-+]+|$)`,
    'i'
);

vk.updates.on('message', (context, next) => {
    if (context.isChat && !mentionPattern.test(context.text)) {
        return;
    }

    if (context.text) {
        context.text = context.text.replace(mentionPattern, '');   
    }

    return next();
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question