0.0.38 โ€ข Published 2 years ago

dialute v0.0.38

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

๐Ÿงถ Dialute

The way you will want to create Chat and Canvas Apps for SberSalute. Use the power of generator based scripts and simple interface of the framework. Based on SmartApp API

โš™๏ธ Install

The framework is published in NPM, thus you can simply install it into your existing

$: npm install dialute

The preferred way to initialize the project is to clone needed template and immediately start development.

$: git clone https://github.com/Dikower/dialute-starter-svelte
# or simply
$: npx degit dikower/dialute-starter-svelte

๐Ÿš€ Startup

Dialute uses Express behind to handle requests from SmartMarket. Thanks to the framework, you can skip all boring and routine stuff about parsing request bodies and managing sessions of users and focus on logic and dialog creation using JavaScript Generators. If you are using example or template and familiar with ngrok, just run

# Shell โ„–1
$: npm run dev

#-------------
# Shell โ„–2
$: ngrok http 8000

๐Ÿ’Ž Concept

The generator represents a dialog. When a user sends a message it triggers the update of SberRequest object, that is passed to the generator as reference. That's why you can easily read the updated message from the same variable. On the other hand, yield will return the content, you pass to user, and then will wait until next message to continue executing script. The generator saves context inside, so it helps us to construct state dependent dialog using just plain JavaScript or TypeScript

  • Import the framework starter and SberRequest for type annotation
    import { Dialute, SberRequest } from 'dialute';
  • Write a generator, that describes the dialog. It must have one required argument: SberRequest and one optional argument Context, you can
      // You can use any name for generator you want
      // r: this is a ref for SberRequest, it will be updated after each user message
      // ctx: Optional argument for advanced techniques, you can skip it for now
      // function* script(r: SberRequest, ctx: any) {
      function* script(r: SberRequest) { // Also possible
        while (true) {
          // send the message to user 
          yield 'Hello world from Dialute!';
          // yield r.msg  // This will make echo-bot, that repeats user input
        }
      }
  • Set the entrypoint of dialog and start the server

    // Creates ready to start server from generator
    const d = Dialute.fromEntrypoint(script as GeneratorFunction);
    // Starts listening for requests from SmartMarket
    d.start();
  • Use nodemon in package.json scripts to enable hot reload

    "scripts": {
      "dev": "nodemon --exec npx ts-node src/index.ts",
    }
  • Run ngrok tunnel on port 8000. Paste https link into Webhook field in SmartApp settings.
    $: ngrok http 8000
  • The whole code can be found inside example directory

๐Ÿ“‹ Docs

https://dialute.vercel.app

๐Ÿฅฐ Support

You can always click on the โญ๏ธ of the repo and donate. I will be very glad for any support

"Buy Me A Coffee"

0.0.37

2 years ago

0.0.38

2 years ago

0.0.32

2 years ago

0.0.33

2 years ago

0.0.34

2 years ago

0.0.35

2 years ago

0.0.36

2 years ago

0.0.30

2 years ago

0.0.31

2 years ago

0.0.26

2 years ago

0.0.27

2 years ago

0.0.28

2 years ago

0.0.29

2 years ago

0.0.21

3 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

0.0.20

3 years ago

0.0.18

3 years ago

0.0.19

3 years ago

0.0.17

3 years ago

0.0.14

3 years ago

0.0.14-d

3 years ago

0.0.15

3 years ago

0.0.16

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.3

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.6

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago