Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
wiki:software:beuthbot:registry [23.01.2020 11:02] Timo Bruns |
wiki:software:beuthbot:registry [23.01.2020 15:32] (aktuell) Timo Bruns |
||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
===== Registry | ===== Registry | ||
- | The **gateway** itself | + | The **registry** is part of the BeuthBot |
==== Table Of Content ==== | ==== Table Of Content ==== | ||
- | + | - [[wiki: | |
- | - [[wiki: | + | |
- | - [[wiki: | + | |
- | - [[wiki: | + | - [[wiki: |
- | - [[wiki: | + | - [[wiki: |
- | - [[wiki: | + | - [[wiki: |
- | - [[wiki: | + | |
- | - [[wiki: | + | |
- | - [[wiki: | + | |
- | - [[wiki: | + | |
- | - [[wiki: | + | |
- | - [[wiki: | + | |
- | - [[wiki: | + | |
- | - [[wiki: | + | |
- | - [[wiki: | + | |
- | - [[wiki: | + | |
- | - [[wiki: | + | |
- | - [[wiki: | + | |
- | - [[wiki: | + | |
==== Getting Started ==== | ==== Getting Started ==== | ||
- | The following sections will give an overview how the gateway was created. It is strongly recommended to read [[https:// | ||
- | \\ | ||
- | Every time a [[https:// | ||
- | \\ | ||
- | 1. //Long polling//\\ | ||
- | 2. // | ||
- | |||
- | Within this project we are going to use webhooks. | ||
=== Prerequisites === | === Prerequisites === | ||
- | Since the gateway is built from scratch there are no specific requirements or dependencies. | + | - [[https:// |
+ | - [[https:// | ||
+ | - [[https:// | ||
- | [// | + | === Cloning === |
- | :!: FIXME FIXME FIXME | + | Get the source code by cloning its repository via https: [[https:// |
- | === Telegram Bot === | ||
- | As mentioned [[wiki: | + | === Installing === |
- | === Set Up === | + | After cloning the repository, you will need to make sure that you have node and npm installed on your working system. To check if you already have node installed, try |
- | Once a [[https:// | + | '' |
- | \\ | + | |
- | The content of this file was looking very rudimentary in the beginning. It simply repsents a ' | + | |
- | \\ | + | |
- | At this point we were able to run our server locally by typing in ''> | + | |
- | \\ | + | |
- | Once this is done we have to let telegram know that our bot has to talk to this url whenver it receives any message in a last step. This get managed through '' | + | |
- | === References === | + | Same for checking if npm is installed, just with npm instead of the node command |
- | During the implementation of the **gateway** we used [[https:// | + | '' |
- | ==== Overview ==== | + | If you don't have node or npm installed, download the Softare via the links provided in [[wiki: |
- | The **gateway** we built is able to receive incoming messages from our bot and also standardizes (since there is no guarantee for uniform requests, | + | After that install |
- | ==== Structure ==== | + | '' |
- | To give a better overview of how the gateway is built up, the following class diagram has been created: | + | Now you can start the local development server to play around with the API and make your calls |
- | < | + | '' |
- | title Gateway - Class Diagram | + | |
- | class StandardizationLayer_Bot { | + | This will fire up a development server that listens on port 3000. |
- | +defaultMessage: | + | |
- | +TextAudioFlag: | + | |
- | -standardizeMessage(): | + | |
- | +getStandardizedMessage(): | + | |
- | -getAudioMessage(): | + | |
- | } | + | |
- | class Gateway { | ||
- | -standardizedMessage: | ||
- | -evaluateScores(): | ||
- | } | ||
- | class LanguageProcessing{ | ||
- | -interpretMessage(): | ||
- | +getInterpretedMessage(): | ||
- | -patternMessage(): | ||
- | +getPatternedMessage(): | ||
- | } | ||
- | class Registry { | + | ==== Overview ==== |
- | + | The registry was built as a regular machine for the chatbot. Here it is decided | |
- | } | + | ==== Structure ==== |
- | + | The registry consists of two files of a JavaScript file which reflects the service. And a Json file which contains | |
- | StandardizationLayer -- Gateway | + | |
- | Gateway -- LanguageProcessing | + | |
- | LanguageProcessing -- Gateway | + | |
- | Gateway -- Registry | + | |
- | </ | + | |
- | + | ||
- | This class diagram shows the structure around | + | |
==== Functionalities ==== | ==== Functionalities ==== | ||
- | === Variables === | + | The registry forwards the incoming requests as a request to the various services and waits for their response before forwarding them to the requester. |
- | The defined variables are based on '' | ||
- | <code javascript> | ||
- | var express = require(' | ||
- | var app = express() | ||
- | var bodyParser = require(' | ||
- | const axios = require(' | ||
- | </ | ||
- | === API-Call === | ||
- | Each time our bot is mesaged | + | ==== Further Development ==== |
+ | To be able to offer further services the corresponding intent only needs to be included | ||
- | <code javascript> | ||
- | app.post('/ | ||
- | const { message } = req.body | ||
- | if (!message || message.text.length < 1) { // In case a message is not present, or if our message is empty, do nothing and return an empty response | ||
- | return res.end() | ||
- | } | ||
- | </ | ||
- | === Microsoft Azure - Cognitive Services - Headers === | ||
- | Microsot Azure predetermines its specific header that should be used for '' | + | ==== Further Reading ==== |
+ | -[[https:// | ||
- | <code javascript> | ||
- | const options = { | ||
- | headers: { | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | === HTTP-POST === | ||
- | |||
- | This section of code shows a request to the Azure service and generates a response which is sent directly to the bot. The code is shaded like this because Axios processes the messages asyncronous and we have to ensure a response has already been received. The following code snippet shows this more in detail: | ||
- | |||
- | <code javascript> | ||
- | axios.post(' | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | }] | ||
- | }, options).then(function (response) { | ||
- | message_out = " | ||
- | axios.post(' | ||
- | chat_id: message.chat.id, | ||
- | text: message_out | ||
- | }).then(response => { | ||
- | // We get here if the message was successfully posted | ||
- | console.log(' | ||
- | res.end(' | ||
- | }) | ||
- | }) | ||
- | }) | ||
- | </ | ||
- | |||
- | === Server === | ||
- | |||
- | The server is listening on port '' | ||
- | |||
- | <code javascript> | ||
- | // Finally, start our server | ||
- | app.listen(3000, | ||
- | console.log(' | ||
- | }) | ||
- | </ | ||
- | |||
- | ==== Further Development ==== | ||
- | |||
- | In the short term, we are considering replacing Azure with Rasa to test the modular requirements. It is later considered that we will connect an NLU adapter that compares the two services and takes the best results. | ||
- | |||
- | ==== Further Reading ==== | ||
- | To get a deeper insight into the technical components of our gateway, we recommend to follow up with some of the topics that are mentioned [[wiki: | ||
==== Built With ==== | ==== Built With ==== | ||
- | - [[https:// | ||
- [[https:// | - [[https:// | ||
- [[https:// | - [[https:// | ||
- [[https:// | - [[https:// | ||
- [[https:// | - [[https:// | ||
- | - [[https:// | + | |
- | - [[https:// | + | |
- | - [[https:// | + | |
==== Versioning ==== | ==== Versioning ==== | ||
- | We use [[https://git.ziemers.de/|GitLab]] for versioning. | + | We use [[https://github.com/|GitHub]] for versioning. |
==== Authors ==== | ==== Authors ==== | ||
- | - **Christopher Lehmann** - //Development// & //Documentation//\\ | + | **Timo Bruns** - //Initial work// - [[https://github.com/Tarry93|GitHub]] |
\\ | \\ | ||
- | - **Timo Bruns** - //Development//\\ | + | **Christopher Lehmann** - //Initial work// - [[https://github.com/Chr1ssy|GitHub]]\\ |
+ | See also the list of [[https:// | ||
+ | <WRAP pagebreak></ |