1.2.4 • Published 11 months ago

wolt-cibus-loader v1.2.4

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

WoltCibusLoader

This project is here to help you and load your cibus extra credits to wolt.

After a few thousands shekels have been lost due to expiery of cibus credits, I decided to autotmate the process (which regardless, is cumbersome and painfull), and save my food money.

NOTE: Unfortunately, wolt login process is not fully automated, and requires user interaction (via telegram bot). This is due to the fact that wolt probably has a bot detection mechanism, which prevent emails to be sent from a non-human source. If you have any ideas on how to bypass and automate this process, please let me know.

Prerequisites

  • Node.js >= 18.x installed.
  • Wolt & Cibus accounts
  • Telegram

    • New bot API token (super easy tutorial)
    • Your telegram user chatId (just message this bot)
  • Google cloud project with the following:

    • Enabled Gmail API
    • OAuth conset screen
    • google-credentials.json file with app credentials in your project root folder
    • token.json file with user access token & refresh token (generated on first run)

    To acheive all of the above, please follow this quickstart guide just up untill "Install the client library"

Installation

npm

npm install wolt-cibus-loader --save

yarn

yarn add wolt-cibus-loader

Usage

First run

import { WoltCibusLoader } from "wolt-cibus-loader";

(async function () {
  try {
    const woltCibusLoader = new WoltCibusLoader({
      woltEmail: process.env.WOLT_EMAIL,
      cibusScraperOptions: {
        username: process.env.CIBUS_USERNAME,
        password: process.env.CIBUS_PASSWORD,
        company: process.env.CIBUS_COMPANY,
      },
      telegramBot: {
        token: process.env.TELEGRAM_BOT_TOKEN,
        userChatId: Number(process.env.TELEGRAM_USER_CHAT_ID),
      },
      allowCreditCardCharge: false,
      dryRun: true,
      shouldReedemCode: true,
    });
    const orderConfirmationNumber = await woltCibusLoader.loadRemainingCibusBalanceToWolt();
    console.log(
      `Successfully loaded remaining Cibus balance to Wolt. Order confirmation number: ${orderConfirmationNumber}`
    );
  } catch (e: any) {
    console.error(`Error loading remaining Cibus balance to Wolt: ${e.message}`);
  }
})();

In order to authorize the app to access your gmail account, and save the credentials for future use, the first run should be done manually.

make sure google-credentials.json is present in your root directory.

You will first be notified by the telegram bot to initiate email login in wolt. After the email is sent, you should click the "ack" button in the telegram message. (Do not open the email or click the link that is sent to you, the whole point is to automate this process).

After aknowledging, you will be prompted to login to your Gmail account, and allow the app to access your email. Once you have done that, the app will save the credentials and you will be able to run the app with minimal user interaction.

*You will notice a token.json file created in your root directory, this file contains the user access token and refresh token, and will be used for future runs, and user interaction will not be needed. You should keep this file safe and not share it with anyone.

IMPORTANT: Don't forget to add the token.json and google-credentials.json to your .gitignore file!

Subsequent runs

Just remove the dryRun option, and you are good to go.

Docker

Feel free to use the example main.ts & Dockerfile to create a docker image and use it as you please.

API

WoltCibusLoader

Constructor

new WoltCibusLoader(config: WoltCibusLoaderConfig)

WoltCibusLoaderConfig

NameTypeDefaultDescription
woltEmailstring (required)-Wolt user email.
cibusScraperOptionsCibusScraperOptions (optional)undefinedOptions for the cibus scraper in order to get current balance and login to the cibus website.
balanceToLoadnumber (optional)undefinedCibus balance to load to Wolt. If not provided, the balance will be fetched from the cibus website.
allowCreditCardChargeboolean (optional)falseWhether to find a gift card with price higher than the balance, charging the remaining balance with a credit card.This is useful if you have a credit card assosiated to your cibus account, and you want to avoid remaining balance in Cibus.
maxCreditCardChargenumber (optional)50The max amount to charge with the credit card.If no gift card is found in the given price range, the first lower price gift card will be used.
shouldReedemCodeboolean (optional)trueWhether the code should be retrieved from the gift card mail and redeemed automatically.
getWoltLoginMagicLinkfunction (optional)undefinedFunction that returns the magic link from the login email received. This or telegramBot must be provided.
telegramBot{ token : string, userChatId : number}undefinedTelegram bot details. This or getWoltLoginMagicLink must be provided.
puppeteerLaunchOptionsPuppeteerLaunchOptionsundefinedPuppeteer launch options to be passed to the puppeteer.launch function.
dryRunbooleanfalseIf true, the flow will be executed without actually submitting the order, it will only log the submitted details.

Methods

loadRemainingCibusBalanceToWolt(): Promise<string>
  • Main method to load the remaining cibus balance to wolt.

License

The MIT License

1.2.4

11 months ago

1.2.3

11 months ago

1.2.2

11 months ago

1.2.1

11 months ago

1.2.0

12 months ago

1.1.3

12 months ago

1.1.2

12 months ago

1.1.1

12 months ago

1.1.0

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago