CSML-by-Clevy / csml-engine

CSML is an easy-to-use chatbot programming language and framework.

Home Page:https://csml.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

csml-server self-host installation on ubuntu: API call fails

solyarisoftware opened this issue · comments

Hi!

I just installed last CSML server version v1.6.3 on ubuntu, following instructions here:
https://blog.csml.dev/how-to-install-a-self-hosted-csml-engine-on-ubuntu-18-04/

I installed mongo db:

$ mongo
MongoDB shell version v4.4.6
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("5fc71c7e-9b57-4567-9f4b-02923f7332a2") }
MongoDB server version: 4.4.6

I configured the environment vars

$ cat .env
ENGINE_DB_TYPE=mongodb
ENGINE_SERVER_PORT=5000

MONGODB_HOST=localhost
MONGODB_PORT=27017
MONGODB_DATABASE=csml
MONGODB_USERNAME=root
MONGODB_PASSWORD=root

ENCRYPTION_SECRET=asomething secret>
DISABLE_SSL_VERIFY=false
DEBUG=true

not if I run the curl example suggested in the article:

curl -X "POST" "http://localhost:5000/run" \
     -H 'content-type: application/json' \
     -d $'{
  "bot": {
    "default_flow": "Default",
    "id": "mybot",
    "name": "MySuperBot"
    "flows": [
      {
        "id": "e0a13373-2037-4590-8018-ab14e74b27a1",
        "content": "start:\\n\\tsay \\"Hello from CSML Server!\\"\\ngoto end",
        "commands": [
          "/default"
        ],
        "name": "Default",
        "description": "Default custom flow"
      }
    ]
  },
  "event": {
    "metadata": {
      "some": "info",
      "about": "the current user"
    },
    "payload": {
      "content": {
        "text": "Hi!"
      },
      "content_type": "text"
    },
    "request_id": "67d283bd-35d5-4744-be61-2f063573022f",
    "client": {
      "user_id": "myuser",
      "channel_id": "mychan",
      "bot_id": "mybot"
    }
  }
}'

$ curlapi.sh 

I do not have any output on the client CLI side, but the server reply a 400 error code:

$ csml-server 
CSML Server listening on port 5000
[2021-06-22T16:55:41Z INFO  actix_web::middleware::logger] 127.0.0.1:59368 "POST /run HTTP/1.1" 400 0 "-" "curl/7.68.0" 0.000184

BTW, I realized that the JSON body example has a wrong syntax, so I corrected it as:

$ cat body.json 
{
  "bot": {
    "default_flow": "Default",
    "id": "mybot",
    "name": "MySuperBot",
    "flows": [
      {
        "id": "e0a13373-2037-4590-8018-ab14e74b27a1",
        "content": "start:\\n\\tsay \\"Hello from CSML Server!\\"\\ngoto end",
        "commands": [
          "/default"
        ],
        "name": "Default",
        "description": "Default custom flow"
      }
    ]
  },
  "event": {
    "metadata": {
      "some": "info",
      "about": "the current user"
    },
    "payload": {
      "content": {
        "text": "Hi!"
      },
      "content_type": "text"
    },
    "request_id": "67d283bd-35d5-4744-be61-2f063573022f",
    "client": {
      "user_id": "myuser",
      "channel_id": "mychan",
      "bot_id": "mybot"
    }
  }
}
$ cat curlapi.sh 
curl -v \
  -X "POST" \
  -H 'content-type: application/json' \
  --data @body.json \
  "http://localhost:5000/run"

but again the server reply a 400 / bad request:

$ curlapi.sh 
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1:5000...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 5000 (#0)
> POST /run HTTP/1.1
> Host: localhost:5000
> User-Agent: curl/7.68.0
> Accept: */*
> content-type: application/json
> Content-Length: 718
> 
* upload completely sent off: 718 out of 718 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 Bad Request
< content-length: 0
< date: Tue, 22 Jun 2021 17:22:16 GMT
< 
* Connection #0 to host localhost left intact

Where I'm wrong?
Thanks!
Giorgio

Hi @solyarisoftware,

I think I found your problem, on your call you use a JSON file directly and you don't need to escape the '' so you only need to replace the bot.flows.content line by

"content": "start:\n\tsay \"Hello from CSML Server!\"\ngoto end",

and thanks for pointing out the syntax error, we updated the post!

Thanks @amerelo
Oh yes usual escaping-related stuff. Problem solved!

Minor collateral points:

  • I'd suggest to insert all installation docs on this github repo, along with the article on the blog, or at least please link the article in this github repo.

  • I propose to show in the / route (the CSML server HTML page with title "CSML Engine") some info showing that the server is up & running, connected to the db etc.

Regards
giorgio

Thanks for the suggestions @solyarisoftware !

The next CSML version is actually mostly about helping users setup/use CSML offline, so we'll make sure to include all that (and much more) 😉

Hey @solyarisoftware you will be happy to learn that we added your suggestions 😃

  • link to blog post is now in the readme!
  • CSML Server now has a GET /status route to check that your configuration is OK #322

Thanks for your contribution!