> For the complete documentation index, see [llms.txt](https://mswag.gitbook.io/hackathon/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mswag.gitbook.io/hackathon/chat-bot-einrichtung.md).

# Chat Bot Einrichtung

Basis-Konfiguration von Heroku, Wit und Telegram Bot

## Inhalt

* [Heroku](/hackathon/chat-bot-einrichtung.md#heroku)
* [Wit](/hackathon/chat-bot-einrichtung.md#wit)
* [Telegram](/hackathon/chat-bot-einrichtung.md#telegram)
* [Heroku Webhook](/hackathon/chat-bot-einrichtung.md#heroku-webhook-einrichtung)

## Heroku

### Account und App Einrichtung

* Erstelle ein Account auf Heroku
* Gehe zu deinem [Dashboard](https://dashboard.heroku.com/apps)
* Klicke oben rechts auf "**New**" -> "**Create new app**"&#x20;

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9EmfwpQ-30FyF6ZA_o%2F-L9Enfd0FhCbvJm9SiUg%2FScreen%20Shot%202018-03-12%20at%2016.28.24.png?alt=media\&token=54892216-8e6e-4fee-bad4-6976286bd30a)

* Wähle einen App Namen
* Klicke auf "**Create app**"

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9EmfwpQ-30FyF6ZA_o%2F-L9Eoe48K2suLCdV1CF2%2FScreen%20Shot%202018-03-12%20at%2016.28.05.png?alt=media\&token=6e8f2556-611e-4975-91ef-5e5bf7b1386c)

* Gehe zu deiner erstellten App&#x20;
* Wähle im Reiter "**Deploy**"
* Und selektiere GitHub aus

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9EmfwpQ-30FyF6ZA_o%2F-L9EpGNdnsYRhKawbGkR%2FScreen%20Shot%202018-04-04%20at%2010.44.45.png?alt=media\&token=09ade560-73a0-4ba5-82b2-956afd3f4d53)

* Erstelle ein Fork von [Clever Tanken Chat Bot](https://github.com/mswag/clever-tanken-bot) Repo

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9EmfwpQ-30FyF6ZA_o%2F-L9EqhI1z96hW8HG3hHE%2FScreen%20Shot%202018-04-04%20at%2010.48.45.png?alt=media\&token=5a2f6849-bfb2-451b-8fdb-1300fba989a5)

* Clone locally dein forked Repo

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9FCnNgOcdsCN90vtNv%2F-L9FO2iPriaV271uyzW7%2FScreen%20Shot%202018-04-04%20at%2013.19.18.png?alt=media\&token=33e2e9d9-c90b-4229-b95a-6483058f9851)

* Geht auf **Terminal**
* Führe folgende Commands aus&#x20;

  ```
  git clone <repo url>
  ```

### Verbindung mit GitHub

* Kehre zurück zu deiner App auf [Heroku](https://dashboard.heroku.com/apps)
* Klicke auf das GitHub Zeichen um dich mit deinem GitHub Account zu verbinden
* Suche Nach deinem Clever Tanken Bot Repo&#x20;
* Und klicke auf "**Connect**"

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9EmfwpQ-30FyF6ZA_o%2F-L9ErXoyxjzsBqZLESnF%2FScreen%20Shot%202018-03-12%20at%2016.30.37.png?alt=media\&token=54c4bece-fc26-42e4-aa74-29e0f013aabc)

* Klicke auf "**Enable Automatic Deploys**"
* Gehe zu dem Reiter Settings und klicke auf den Button "**Add Buildpack**"
* Wähle neue **NodeJS** aus
* Dann klicke auf "**Save Changes**"

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9EmfwpQ-30FyF6ZA_o%2F-L9Es_3NWU1UPhwurd98%2FScreen%20Shot%202018-03-12%20at%2016.38.18.png?alt=media\&token=e4de2a63-002e-4bbb-8f2e-9964c1f7477b)

## Wit&#x20;

* Log dich mit deinem GitHub Account auf [Wit](https://wit.ai) ein
* Gehe zu deinem Profile
* Klicke auf den **Plus Button** oben rechts

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9EmfwpQ-30FyF6ZA_o%2F-L9EtWQXXG2vR2mFnHEr%2FScreen%20Shot%202018-03-13%20at%2016.37.30.png?alt=media\&token=d032eac9-21ac-4864-bc16-84e157a0e9f1)

* Fühle das Feld "**App Name**" aus
* Fühle das Feld "**App Description**" aus
* Klicke auf "**Create App**"

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9EmfwpQ-30FyF6ZA_o%2F-L9Eu2YYOAE2v3Sb6hJL%2FScreen%20Shot%202018-03-15%20at%2014.05.42.png?alt=media\&token=1ee60ba3-269c-408b-b67c-727e5ccb7c7d)

* Gehe zu deinem Profile und wähle deine App aus
* Unter "Test how your app understands a sentence" gebe den satz "**Wie teuer ist Diesel in München**" ein
* Makieren "**Diesel**" in deinem Satz&#x20;

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9EmfwpQ-30FyF6ZA_o%2F-L9EvYVainZwR049rhcy%2F2018-04-04%2011.12.20.jpg?alt=media\&token=46a06b0c-4810-4dd8-88f2-6120a59120e3)

* Klicke auf "**Create an Entitiy for Diesel**"
* Und erstelle eine neue Entity `fuelType`

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9EwZ-cklJlxGDDZvHz%2F-L9EwiAzNtMTnORUfMWp%2FScreen%20Shot%202018-04-04%20at%2011.16.00.png?alt=media\&token=16d8f8d3-6a59-47af-b8fb-49d9c1f6a395)

* Wiederhole diesen Vorgang mit "**München**"
* Benutzte aber dazu die Entity von Wit `wit/location`

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9EwZ-cklJlxGDDZvHz%2F-L9Ex8dt8PIDChfFAMLv%2FScreen%20Shot%202018-04-04%20at%2011.14.54.png?alt=media\&token=32857edb-cb55-468d-821d-c35c6dcebf93)

* Scrolle runter zur Entity Sektion und klicke auf "**fuelType**"
* Wähle als Lookup Strategie **Kewords** aus
* Bestätige dies Aktion&#x20;

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9EwZ-cklJlxGDDZvHz%2F-L9Ey0o3eu2P0pKOrC3S%2FScreen%20Shot%202018-03-23%20at%2010.32.35.png?alt=media\&token=b5ee2c86-3d10-4eef-96d7-c5e725b266f6)

* Scrolle nach unten und Gebe folgende Keywords ein:&#x20;

`Super E5, Erdgas, Premium Diesel, Diesel, AdBlue, Autogas, Super E10, Bioethanol, SuperPlus`

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9EwZ-cklJlxGDDZvHz%2F-L9EyCd2YGyV_Ei2C1yS%2FScreen%20Shot%202018-03-23%20at%2010.34.28.png?alt=media\&token=889b3992-b6d7-4463-8b90-09cc241778c8)

## Telegram

* Erstelle einen [Telegram](https://telegram.org) Account über die [Android](https://play.google.com/store/apps/details?id=org.telegram.messenger)/[iOS](https://itunes.apple.com/app/telegram-messenger/id686449807) App du kannst später auch eine [Desktop Client](https://telegram.org/apps#desktop-apps) zum Einrichten/Testen benutzten. **Vorsicht!** mit dem Desktop Client kann man kein Telegram Account erstellen
* Suche nach dem User [@botfather](https://telegram.me/botfather)
* Klicke auf den Button **"Start"**
* Gebe den Kommand `/newbot` ein
* Gebe deinen Bot Namen an und den Username&#x20;
* Speichere den **Token** zwischen

## Heroku Webhook Einrichtung

* Kehre zu deiner Heroku App zurück&#x20;
* Klicke auf "**More**"->"**Run Console**"
* Führe folgende Commands aus (\*)&#x20;

```
npm install -g bottender
```

\*Falls das nicht funktioniert, check ob die App deployed wurde. Wenn nicht, versucht es manuell zu deployen:

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9FCnNgOcdsCN90vtNv%2F-L9FPkgz2V24teMq_6wn%2FScreen%20Shot%202018-04-04%20at%2011.50.04.png?alt=media\&token=515e4def-1c49-480b-9b4c-8b1e6bebcff7)

Wenn du herausfinden willst was deine App URL ist dann klicke oben rechts auf "**Open App**" und kopiere die URL:

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9FCnNgOcdsCN90vtNv%2F-L9FRBtM7SHYR4K8Umqa%2FScreen%20Shot%202018-04-04%20at%2013.34.51.png?alt=media\&token=ad56e318-c181-495d-9df0-4ee7dde0299e)

* Kehre zur Console zurück und führe den Command aus:

```
bottender telegram webhook set -w {deine app url}
```

## Bot Konfiguration: App Token

* Auf deinem Rechner, gehe auf deine gecloned Files: `cd ~/clever-tanken-bot`
* Unter bot, ändert den File config.json:
* `{`\
  &#x20;`"Telegram": { "accessToken": "`**`TOKEN FROM BOTFATHER HERE`**`" },`\
  &#x20;`"Messenger": { "accessToken": "", "appSecret": "", "verifyToken": "" }`\
  `}`
* Gehe zu **Wit.ai -> Settings** und hol das Server Access Token für die App:

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9FCnNgOcdsCN90vtNv%2F-L9FS-wskI2l50H8djOu%2FScreen%20Shot%202018-04-04%20at%2013.37.10.png?alt=media\&token=9a6e20d7-9860-4284-b1b9-848acdad9c09)

* Gib den Code in die Konfiguration ein `/clever-tanken-bot/utilities/wit.js`:

`const WitClient = new Wit({` \
&#x20;   `accessToken: "`**`SERVER ACCESS TOKEN`**`",` \
&#x20;   `logger: new log.Logger(log.DEBUG)`\
`})`

* Speiche die Änderung und pushe zu dein git Repo

## Los geht's

* Die App sollte  deployed werden und der Bot sollte testbar sein
* Suche dein Bot auf Telegram (@deinbotname) und check es:

![](https://1340393511-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9Ehq3G2ztBXuvjVEph%2F-L9FCnNgOcdsCN90vtNv%2F-L9FT1pNJu7LadZET0iR%2FScreen%20Shot%202018-04-04%20at%2013.42.46.png?alt=media\&token=462ec533-6276-4e0d-9a4b-2dc029447429)

Wir benutz [Bottender](https://bottender.js.org) als Framework [hier](https://bottender.js.org/docs/APIReference-Context) ein Link zur Dokumentation
