How to use the telegraf/composer.privateChat function in telegraf

To help you get started, we’ve selected a few telegraf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github N3TC4T / xrp-telegram-bot / handlers / scenes / send.js View on Github external
stepOne() {
        const stepOneHandler = new Composer();
        stepOneHandler.hears(CANCEL_TEXT, Composer.privateChat(this.Cancel));
        stepOneHandler.on(
            'message',
            Composer.privateChat(async ctx => {
                const message = ctx.update.message.text;
                const username = message.replace('@', '');

                const userModel = new this.db.User();
                const from_user = await userModel.getUser(ctx);

                if (!/^[a-zA-Z0-9_-]{5,32}$/.test(username)) {
                    return ctx.replyWithHTML('⚠️ Please enter a valid telegram username. Ex: @n3tc4t', CANCEL_MENU);
                }

                if (from_user.username) {
                    if (from_user.username.toLowerCase() === username.toLowerCase()) {
                        return ctx.replyWithHTML(`️️️️⚠️ You can not send XRP to yourself!`, CANCEL_MENU);
                    }
                }
github N3TC4T / xrp-telegram-bot / handlers / scenes / send.js View on Github external
stepOne() {
        const stepOneHandler = new Composer();
        stepOneHandler.hears(CANCEL_TEXT, Composer.privateChat(this.Cancel));
        stepOneHandler.on(
            'message',
            Composer.privateChat(async ctx => {
                const message = ctx.update.message.text;
                const username = message.replace('@', '');

                const userModel = new this.db.User();
                const from_user = await userModel.getUser(ctx);

                if (!/^[a-zA-Z0-9_-]{5,32}$/.test(username)) {
                    return ctx.replyWithHTML('⚠️ Please enter a valid telegram username. Ex: @n3tc4t', CANCEL_MENU);
                }

                if (from_user.username) {
                    if (from_user.username.toLowerCase() === username.toLowerCase()) {
                        return ctx.replyWithHTML(`️️️️⚠️ You can not send XRP to yourself!`, CANCEL_MENU);
github N3TC4T / xrp-telegram-bot / handlers / scenes / withdraw.js View on Github external
stepFour() {
        const stepFourHandler = new Composer();

        stepFourHandler.hears(CANCEL_TEXT, Composer.privateChat(this.Cancel));
        stepFourHandler.action('confirm-withdraw-no', Composer.privateChat(this.Cancel));

        stepFourHandler.action(
            'confirm-withdraw-yes',
            Composer.privateChat(async ctx => {
                const { replyWithHTML } = ctx;
                const { state } = ctx.scene.session;

                const unlock = await ctx.session.lock();

                try {
                    const userModel = new this.db.User();
                    const user = await userModel.getUser(ctx);

                    if (parseFloat(user.balance) < parseFloat(state.amount)) {
                        return this.Cancel(ctx);
                    }

                    const withdraw = {
                        source_tag: user.telegramId,
                        amount: state.amount,
github N3TC4T / xrp-telegram-bot / handlers / scenes / feed_notify.js View on Github external
setHandler() {
        this.app.hears(CANCEL_TEXT, Composer.privateChat(this.Cancel));
        this.app.hears(
            'ℹ️ Feed Notify',
            Composer.privateChat(async ctx => {
                const { scene } = ctx;
                scene.enter('feed_notify');
            }),
        );
    }
}
github N3TC4T / xrp-telegram-bot / handlers / scenes / wallet_notify.js View on Github external
deleteHandler() {
        const deleteHandler = new Composer();

        deleteHandler.hears(CANCEL_TEXT, Composer.privateChat(this.Menu));
        deleteHandler.action('confirm-delete-wallet-no', Composer.privateChat(this.Menu));

        deleteHandler.action(
            'confirm-delete-wallet-yes',
            Composer.privateChat(ctx => {
                const { state } = ctx.scene.session;

                const walletNotifyModel = new this.db.WalletNotify();
                walletNotifyModel.deactiveNotify(state.id);
                ctx.replyWithHTML('✅ Wallet Successfully removed!');
                this.Menu(ctx);
            }),
        );
        return deleteHandler;
    }
github N3TC4T / xrp-telegram-bot / handlers / scenes / wallet_notify.js View on Github external
deleteHandler() {
        const deleteHandler = new Composer();

        deleteHandler.hears(CANCEL_TEXT, Composer.privateChat(this.Menu));
        deleteHandler.action('confirm-delete-wallet-no', Composer.privateChat(this.Menu));

        deleteHandler.action(
            'confirm-delete-wallet-yes',
            Composer.privateChat(ctx => {
                const { state } = ctx.scene.session;

                const walletNotifyModel = new this.db.WalletNotify();
                walletNotifyModel.deactiveNotify(state.id);
                ctx.replyWithHTML('✅ Wallet Successfully removed!');
                this.Menu(ctx);
            }),
        );
        return deleteHandler;
    }
github N3TC4T / xrp-telegram-bot / handlers / scenes / wallet_notify.js View on Github external
addHandler() {
        const addHandler = new Composer();
        addHandler.hears(CANCEL_TEXT, Composer.privateChat(this.Menu));
        addHandler.on(
            'message',
            Composer.privateChat(async ctx => {
                const message = ctx.update.message.text;
                if (!address_codec.isValidAddress(message)) {
                    return ctx.reply('⚠️ Please enter a correct XRP address.');
                }

                const userModel = new this.db.User();
                const user = await userModel.getUser(ctx);

                const walletNotifyModel = new this.db.WalletNotify();
                const status = await walletNotifyModel.activeNotify(user.id, message);
                if (status) {
                    await ctx.replyWithHTML(
                        `✅ Wallet Address <b>${message}</b> successfully added.\nAfter this You will get notification on payment transactions on this wallet.`,
                    );
                } else {
                    await ctx.replyWithHTML(`Wallet Address <b>${message}</b> is already in your notify list.`);
github N3TC4T / xrp-telegram-bot / handlers / scenes / feed_notify.js View on Github external
actionHandler() {
        const actionHandler = new Composer();

        actionHandler.hears(CANCEL_TEXT, Composer.privateChat(this.Menu));
        actionHandler.action('confirm-unsubscribe-no', Composer.privateChat(this.Menu));
        actionHandler.action('confirm-subscribe-no', Composer.privateChat(this.Menu));

        actionHandler.action(
            'confirm-unsubscribe-yes',
            Composer.privateChat(ctx => {
                const from = ctx.update.callback_query.from;
                const subscriptionsModel = new this.db.Subscriptions();
                subscriptionsModel.setSettings(from.id, false);
                ctx.replyWithHTML('You successfully unsubscribed from this feed');
                this.Menu(ctx);
            }),
        );

        actionHandler.action(
            'confirm-subscribe-yes',
            Composer.privateChat(ctx => {
                const from = ctx.update.callback_query.from;
github N3TC4T / xrp-telegram-bot / handlers / scenes / feed_notify.js View on Github external
actionHandler() {
        const actionHandler = new Composer();

        actionHandler.hears(CANCEL_TEXT, Composer.privateChat(this.Menu));
        actionHandler.action('confirm-unsubscribe-no', Composer.privateChat(this.Menu));
        actionHandler.action('confirm-subscribe-no', Composer.privateChat(this.Menu));

        actionHandler.action(
            'confirm-unsubscribe-yes',
            Composer.privateChat(ctx => {
                const from = ctx.update.callback_query.from;
                const subscriptionsModel = new this.db.Subscriptions();
                subscriptionsModel.setSettings(from.id, false);
                ctx.replyWithHTML('You successfully unsubscribed from this feed');
                this.Menu(ctx);
            }),
        );

        actionHandler.action(
            'confirm-subscribe-yes',
            Composer.privateChat(ctx => {
github N3TC4T / xrp-telegram-bot / handlers / scenes / wallet_notify.js View on Github external
setHandler() {
        this.app.hears(CANCEL_TEXT, Composer.privateChat(this.Cancel));
        this.app.hears(
            '➕ Add Wallet',
            Composer.privateChat(ctx => {
                const { scene } = ctx;
                scene.enter('wallet_notify_add');
            }),
        );

        this.app.hears(
            '📇 Manage Wallets',
            Composer.privateChat(ctx => {
                const { scene } = ctx;
                scene.enter('wallet_notify_delete');
            }),
        );
    }