Moving to Berlin using ChatGPT and JavaScript
Tags: programming, chatgpt, automation, javascript
Published: 2023-12-11 09:24:46

**TLDR**: I built a bot that automatically sends personalized, context-aware messages to every new listing posted on [wg-gesucht.de](https://www.wg-gesucht.de/). The bot found me a flat in Berlin!

> If you’re interested in the technical side of this project, feel free to <a href="https://github.com/isaksolheim/gesucht">dig through the code</a> while reading this article!

## Intro

As my exchange semester at Technische Universität Berlin approached, I started looking for places to live. Without an existing network in Berlin, I used the website [wg-geuscht.de](https://www.wg-gesucht.de/) to contact potential flatshares. This was a very repetitive process, and I decided to automate it.

## Automate the Boring Stuff with JavaScript

I set up email alerts for all new potential flats in my price range on [wg-gesucht.de](https://www.wg-gesucht.de/), and used Google Clouds [Pub/Sub service](https://cloud.google.com/pubsub/docs/overview) with a [push subscription](https://cloud.google.com/pubsub/docs/push) to watch for any incoming email to my Gmail inbox.

Once a new email arrives, the service sends a webhook notification to my server.

### Parsing the email

On the server, written in JavaScript with [Express](https://github.com/expressjs/express), I read the latest email in my Gmail inbox and parse it with Regex to see if the email contains links to any wg-geuscht listings.

### Navigating the listing

For each listing, I spawn a chromium browser using [Playwright](https://playwright.dev/), an end-to-end testing framework. This allows me to navigate the website just as one would when interacting with it themselves. I sign into my account, take note of the listing description, and hit send message.

### Generating a message using GPT-3.5 Turbo

The message is generated using [GPT-3.5 Turbo](https://platform.openai.com/docs/models/gpt-3-5) with the following prompt:

```javascript
const prompt = `
Can you spice up the following text: "${starterText}"
The updated text should explain why I would fit in the
flatshare with the following listing text: "${listingText}".
Add some emojies as well. Mention that my semester is from
September to March, so a stay for that perioud would be ideal
(but Im always flexible)! And if the listing is written in
German, the answer should be in German as well. And if the 
listing says I need to say a specific word, start the whole 
text with that word!
`;
```

The generated message was sent alongside a couple of images of myself.

## The result

The time it took from a listing went live to my bot had sent a response was around 10 seconds, making me confident in being the first responder. This was the response that secured me a flat:

```
Hallo zusammen! 🦄

Das scheint ja eine richtig coole WG zu sein, in die ich perfekt reinpassen würde! 😄

Ich bin Isak und ich glaube, dass ich perfekt in dein WG-Zimmer passen würde! Mein Semester in Berlin geht von September bis März, also wäre ein Aufenthalt für diesen Zeitraum ideal (aber ich bin auch immer flexibel!). Die Lage der Wohnung klingt super, besonders die Nähe zum RAW-Gelände und zum Boxhagener Platz. Und hey, eine Tram-Station direkt vor der Tür ist auch genial! 🚋

Die Wohnung hört sich toll an, mit Balkon, Badewanne und Waschmaschine. Da fühlt man sich doch gleich wie zuhause! Wenn du Interesse hast, würde ich mich freuen, von dir zu hören. 📞

Liebe Grüße und hoffentlich bis bald!

Isak

P.S. Wenn die Anzeige auf Deutsch ist, dann antworte ich auch gerne auf Deutsch. Aber sei gewarnt, mein Deutsch ist manchmal etwas holprig. Ich verstehe nur Bahnhof! 😄
```

## Closing thoughts

Looking back, I spent more time tinkering with the bot than I would have manually responding to email notifications. But with that being said, I am happy with how this project turned out. I got a lot of laughs from the silly responses the bot would send, and the frequency of people getting back to me was noticeably increased (most likely because I was their first responder).

I recently tried spinning the bot up again, but since my search in June, captcha verification has been implemented on their site. This may be for the better. For all I know many of the listings themselves were created using ChatGPT.