Skip to content

Commit

Permalink
feat(bankid): support BankID identification for existing booking
Browse files Browse the repository at this point in the history
BankID is now also required when booking from an existing booking number, this adds support for the BankID step for existing bookings.
  • Loading branch information
kalkih committed May 13, 2022
1 parent def62d3 commit d88d908
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,37 @@ Download `config.json` & `passport-appointment-bot` for your OS from the [latest

1. Edit the configuration file downloaded (`config.json`) with any text editor, see [Configuration](#configuration) for information on the options
2. Run the executable downloaded earlier `passport-appointment-bot`
3. The bot will prompt for BankID identification (BankID is now required in order to book an appointment, unless an existing booking number is provided in the config)
3. The bot will prompt for BankID identification (The booking system now requires BankID idetification to start a booking session)
4. The bot will search until an appointment is found
5. A booking confirmation will be sent to the configured email and/or phonenumber specified in the config, it will also be displayed in the application
5. A booking confirmation will be sent to the configured email and/or phone number specified in the config, it will also be displayed in the application

### Run from source
### (Advanced) Run from source

Requires **Nodejs** _(Tested on v17.7.1)_

1. Clone the project, install dependencies with `npm install`
2. Edit configuration values in `config.json`, see [Configuration](#configuration) for information on the options
3. Run the bot with `npm start`
4. The bot will prompt for BankID identification (BankID is now required in order to book an appointment, unless an existing booking number is provided in the config)
4. The bot will prompt for BankID identification (The booking system now requires BankID idetification to start a booking session)
5. The bot will search until an appointment is found
6. A booking confirmation will be sent to the configured email and/or phonenumber specified in the config, it will also be displayed in the console
6. A booking confirmation will be sent to the configured email and/or phone number specified in the config, it will also be displayed in the console

### Configuration

#### Basic configuration options

| Option | Required | Description |
| -------------- | :------: | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| region | ✅ | Desired region, see [Supported Regions & Locations](#supported-regions--locations) |
| locations | ✅ | One or more cities/locations, see [Supported Regions & Locations](#supported-regions--locations) |
| max_date | ✅ | Latest date to search for appointment (will search all days in the week of the specified date) |
| min_date | ❌ | Earliest date to search for appointment (will search all days in the week of the specified date) |
| booking_number | ❌ | An existing booking number to use when searching for available times. When providing an existing booking number BankID identification is skipped |
| email | ✅ | Email (confirmation will be sent to this address) |
| phone | ✅ | Phone number (confirmation will be sent to this number) |
| passport | ✅ | Set to `true` if the booking appointment is for passport, else `false` |
| id | ✅ | Set to `true` if the booking appointment is for national identity card, else `false` |
| confirmation | ✅ | Method for receiving booking confirmation `email` and/or `sms` |
| Option | Required | Description |
| -------------- | :------: | ------------------------------------------------------------------------------------------------ |
| region | ✅ | Desired region, see [Supported Regions & Locations](#supported-regions--locations) |
| locations | ✅ | One or more cities/locations, see [Supported Regions & Locations](#supported-regions--locations) |
| max_date | ✅ | Latest date to search for appointment (will search all days in the week of the specified date) |
| min_date | ❌ | Earliest date to search for appointment (will search all days in the week of the specified date) |
| booking_number | ❌ | An existing booking number to use when searching for available times. |
| email | ✅ | Email (confirmation will be sent to this address) |
| phone | ✅ | Phone number (confirmation will be sent to this number) |
| passport | ✅ | Set to `true` if the booking appointment is for passport, else `false` |
| id | ✅ | Set to `true` if the booking appointment is for national identity card, else `false` |
| confirmation | ✅ | Method for receiving booking confirmation `email` and/or `sms` |

#### Multiple people booking options

Expand Down
9 changes: 8 additions & 1 deletion src/services/bookingService/existingBookingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import cheerio, { Cheerio, CheerioAPI, Element } from "cheerio";
import { Location } from "../../configuration";
import { logger } from "../../logger";
import { getShortDate } from "../../utils";
import { BankIdService } from "../bankIdService";
import {
BookingPageError,
BookingService,
Expand Down Expand Up @@ -33,13 +34,19 @@ export class ExistingBookingService extends BookingService {
logger.info("Launching session for existing booking...");
await this.getRequest();

const response = await this.postRequest({
const initBookingResponse = await this.postRequest({
FormId: 2,
BookingNumber: this.bookingNumber,
ContactInfo: this.email,
NextButtonID6: "Omboka/Avboka",
});

const sessionId = initBookingResponse.url.split("?sessionid=")[1];
const bankIdService = new BankIdService(sessionId);
const sessionUrl = await bankIdService.identify();

const response = await this.getRequest(sessionUrl);

const $ = cheerio.load(await response.text());
const errors = $(VALIDATION_ERROR_SELECTOR).text();
const nextButtonId = $("input[title='Ändra tid']").attr("name") || "";
Expand Down

0 comments on commit d88d908

Please sign in to comment.