fix(basic.gblib): update ChatServices.ts #420

Closed
eltociear wants to merge 2540 commits from patch-1 into main
292 changed files with 38435 additions and 5336 deletions

View file

@ -1,2 +1,2 @@
[config] [config]
command = deploy.cmd command = bash ./deploy.sh

5
.env
View file

@ -1,5 +0,0 @@
ADMIN_PASS=
ADDITIONAL_DEPLOY_PATH=
DATABASE_DIALECT=sqlite
DATABASE_OBJECT_PREFIX=env1-
DATABASE_SYNC=false

3
.gitattributes vendored Normal file
View file

@ -0,0 +1,3 @@
* text=auto
*.js eol=lf
*.ts eol=lf

35
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View file

@ -0,0 +1,35 @@
---
name: Bug report
about: Create a report to help us improve
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.

7
.github/ISSUE_TEMPLATE/custom.md vendored Normal file
View file

@ -0,0 +1,7 @@
---
name: Custom issue template
about: Describe this issue template's purpose here.
---

View file

@ -0,0 +1,17 @@
---
name: Feature request
about: Suggest an idea for this project
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

2
.github/ISSUE_TEMPLATE/requirement vendored Normal file
View file

@ -0,0 +1,2 @@
**Description**
A clear and concise description of what the requirement is.

View file

@ -6,7 +6,7 @@
Please check if your PR fulfills the following specifications: Please check if your PR fulfills the following specifications:
- [ ] Tests for the changes have been added - [ ] Tests for the changes have been done
- [ ] Docs have been added/updated - [ ] Docs have been added/updated
### References ### References

View file

@ -1,7 +1,7 @@
repository: repository:
name: botserver name: botserver
description: botserver description: botserver
homepage: http://pragmatismo.io/general-bots homepage: http://pragmatismo.cloud/general-bots
topics: node-module topics: node-module
private: false private: false
has_issues: true has_issues: true

34
.gitignore vendored
View file

@ -1,7 +1,31 @@
node_modules /.coveralls.yml
/deploy/default.gbui/build /.env
/.npmrc
/.nyc_output
/coverage
/dist /dist
/guaribas.sqlite
/guaribas.log
/work
/docs /docs
/guaribas.log
/guaribas.sqlite
/node_modules
/packages/default.gbui/build
/packages/default.gbui/.env
/packages/default.gbui/node_modules
/packages/default.gbui/package-lock.json
/packages/default.gbui/yarn-lock.json
/work
*.vbs.compiled
*.vbs.js
*.vbs.ts
.env
*.env
.vscode/launch.json
.wwebjs_auth
GB.log
gb.log
GB.log.json
yarn-error.log
package-lock.json
yarn-lock.json
logo.svg
screenshot.png

9
.hintrc Normal file
View file

@ -0,0 +1,9 @@
{
"extends": [
"development"
],
"hints": {
"typescript-config/strict": "off",
"typescript-config/consistent-casing": "off"
}
}

15
.npmignore Normal file
View file

@ -0,0 +1,15 @@
# This file must be a copy of .gitignore except for the WILLSHIP commented lines below.
/.coveralls.yml
/.env
/.npmrc
# WILLSHIP /.nyc_output
/coverage
# WILLSHIP /dist
/guaribas.log
/guaribas.sqlite
/node_modules
# WILLSHIP /packages/default.gbui/build
/packages/default.gbui/.env
/packages/default.gbui/node_modules
/tmp
/work

8
.prettierrc Normal file
View file

@ -0,0 +1,8 @@
{
"trailingComma": "none",
"tabWidth": 2,
"printWidth": 120,
"arrowParens": "avoid",
"semi": true,
"singleQuote": true
}

33
.travis.yml Normal file
View file

@ -0,0 +1,33 @@
dist: focal
language: node_js
node_js:
- 19.7.0
notifications:
email: false
before_script:
- npm run build
branches:
only:
- main
- /^greenkeeper/.*$/
except:
- /^v\d+\.\d+\.\d+$/
after_success:
- npm install -g travis-deploy-once
- npm run travis-deploy-once "npm run semantic-release"
- npm pack
deploy:
- provider: pages
skip_cleanup: true
local_dir: docs/reference
github_token: $GITHUB_TOKEN
on:
tags: false
branch: main

20
.vscode/launch.json vendored
View file

@ -4,15 +4,25 @@
{ {
"type": "node", "type": "node",
"request": "launch", "request": "launch",
"sourceMaps": true,
"name": "Debug Program", "name": "Debug Program",
"program": "${workspaceRoot}/dist/src/app.js", "runtimeExecutable": "node",
"program": "${workspaceRoot}/boot.mjs",
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"env": { "env": {
"NODE_ENV": "development" "NODE_ENV": "development",
"NODE_NO_WARNINGS":"1"
}, },
"args":["--no-deprecation"], "args": [
"skipFiles": ["node_modules/**/*.js"], "--no-deprecation",
"outFiles": ["${workspaceRoot}/dist/*.js"], "--loader ts-node/esm",
"--require ${workspaceRoot}/suppress-node-warnings.cjs",
],
"skipFiles": [
"node_modules/**/*.js"
],
"outFiles": [
"${workspaceRoot}/dist/**/*.js"],
"stopOnEntry": false, "stopOnEntry": false,
"console": "integratedTerminal" "console": "integratedTerminal"
} }

View file

@ -1,4 +1,3 @@
{ {
"typescript.tsdk": "./node_modules/typescript/lib", "git.ignoreLimitWarning": true
} }

14
.vscode/tasks.json vendored
View file

@ -1,6 +1,20 @@
{ {
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0", "version": "2.0.0",
"tasks": [ "tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"option": "watch",
"problemMatcher": [
"$tsc-watch"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{ {
"type": "typescript", "type": "typescript",
"tsconfig": "tsconfig.json", "tsconfig": "tsconfig.json",

2492
CHANGELOG.md Normal file

File diff suppressed because it is too large Load diff

48
CODE_OF_CONDUCT-pt-br.md Normal file
View file

@ -0,0 +1,48 @@
# Código de Conduta do Convênio do Colaborador
## Nosso Compromisso
No interesse de promover um ambiente aberto e acolhedor, nós, como colaboradores e mantenedores, nos comprometemos a tornar a participação em nosso projeto e em nossa comunidade uma experiência livre de assédio para todos, independentemente de idade, raça, etnia, origem nacional, ascendência, sexo, sexo identidade ou apresentação, orientação sexual, aparência física, afiliação religiosa, credo, estado civil ou familiar, não tolerará abuso ou assédio discriminatório ou sexual contra qualquer pessoa durante quaisquer atividades relacionadas à conferência, incluindo, entre outros, envio, revisão, tutoriais, oficinas ou eventos sociais. O abuso inclui qualquer ação dirigida a um indivíduo que (a) interfira substancialmente na participação dessa pessoa ou (b) faça com que essa pessoa tema por sua segurança pessoal. Isso inclui ameaças, intimidação, intimidação, perseguição ou outros tipos de abuso. Assédio discriminatório inclui qualquer conduta que discrimine ou denigra um indivíduo com base em idade, raça, etnia, nacionalidade, ascendência, gênero, identidade ou apresentação de gênero, orientação sexual, aparência física, afiliação religiosa, credo, estado civil ou familiar, deficiência , características pessoais ou quaisquer outros fatores diferenciadores, bem como qualquer outra característica protegida por lei no local onde ocorre a atividade da conferência. Assédio sexual inclui (mas não se limita a) investidas sexuais indesejadas repetidas, pedidos de favores sexuais ou outra conduta verbal ou física de natureza sexual, deficiência, características pessoais ou quaisquer outros fatores de diferenciação, bem como qualquer outra característica protegida por lei no local onde a atividade ocorre.
## Nossos Padrões
Exemplos de comportamento que contribuem para criar um ambiente positivo incluem:
* Usando linguagem padrão (sem expressões idiomáticas), acolhedora e inclusiva
* Ser respeitoso com os diferentes pontos de vista e experiências
* Aceitar graciosamente críticas construtivas
* Focar no que é melhor para a comunidade
* Mostrar empatia para com outros membros da comunidade
* Escrever trechos gerais de código para que possam ser amplamente utilizados.
Exemplos de comportamento inaceitável por parte dos participantes incluem:
* O uso de linguagem ou imagens sexualizadas e atenção ou avanços sexuais indesejados
* Trolling, comentários insultuosos/depreciativos e ataques pessoais ou políticos
* Assédio (harassment) público ou privado / perseguição (stalking) / intimidação (bullying) / mobbing (group bullying or gang stalking)
* Publicar informações privadas de outras pessoas, como endereço físico ou eletrônico, sem permissão explícita
* Outra conduta que possa ser razoavelmente considerada inadequada em um ambiente profissional
* Chamar uma pessoa de nome diferente do declarado pela pessoa
## Nossas responsabilidades
Os mantenedores do projeto são responsáveis por esclarecer os padrões de comportamento aceitável e devem tomar ações corretivas apropriadas e justas em resposta a quaisquer instâncias de comportamento inaceitável.
Os mantenedores do projeto têm o direito e a responsabilidade de remover, editar ou rejeitar comentários, confirmações, códigos, edições wiki, problemas e outras contribuições que não estejam alinhadas com este Código de Conduta, ou banir temporária ou permanentemente qualquer colaborador por outros comportamentos que eles considerem inapropriado, ameaçador, ofensivo ou prejudicial.
## Escopo
Este Código de Conduta se aplica tanto em espaços do projeto quanto em espaços públicos quando um indivíduo representa o projeto ou sua comunidade. Exemplos de representação de um projeto ou comunidade incluem o uso de um endereço de e-mail oficial do projeto, postagem por meio de uma conta de mídia social oficial ou atuação como um representante nomeado em um evento online ou offline. A representação de um projeto pode ser posteriormente definida e esclarecida pelos mantenedores do projeto.
## Aplicação
Instâncias de comportamento abusivo, de assédio ou inaceitável podem ser relatadas entrando em contato com a equipe de segurança da Pragmatismo em c. A equipe do projeto analisará e investigará todas as reclamações e responderá da maneira que julgar apropriada às circunstâncias. A equipe do projeto é obrigada a manter a confidencialidade em relação ao relator de um incidente. Mais detalhes sobre políticas de execução específicas podem ser publicados separadamente.
Os mantenedores do projeto que não seguirem ou aplicarem o Código de Conduta de boa fé podem enfrentar repercussões temporárias ou permanentes conforme determinado por outros membros da liderança do projeto.
## Atribuição
Este Código de Conduta foi adaptado do [Acordo do Colaborador][homepage], versão 1.4, disponível em [http://contributor-covenant.org/version/1/4][version] e Código de Conduta ICAPS.
[página inicial]: http://contributor-covenant.org
[versão]: http://contributor-covenant.org/version/1/4/

49
CODE_OF_CONDUCT.md Normal file
View file

@ -0,0 +1,49 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, race, ethnicity, national origin, ancestry, gender, gender identity or presentation, sexual orientation, physical appearance, religious affiliation, creed, marital or familial status, will not tolerate abuse or discriminatory or sexual harassment toward any person during any conference-related activities, including but not limited to submission, reviewing, tutorials, workshops, or social events. Abuse includes any action directed at an individual that (a) interferes substantially with that persons participation or (b) causes that person to fear for their personal safety. This includes threats, intimidation, bullying, stalking, or other types of abuse. Discriminatory harassment includes any conduct that discriminates or denigrates an individual on the basis of age, race, ethnicity, national origin, ancestry, gender, gender identity or presentation, sexual orientation, physical appearance, religious affiliation, creed, marital or familial status, disability, personal characteristics, or any other differentiating factors, as well as any other characteristic protected by law in the location where conference activity takes place. Sexual harassment includes (but is not limited to) repeated unwelcome sexual advances, requests for sexual favors, or other verbal or physical conduct of a sexual nature, disability, personal characteristics, or any other differentiating factors, as well as any other characteristic protected by law in the location where activity takes place.
## Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using standard(no idiomatic expressions), welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
* Writing general pieces of code so it can be widely used.
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment / stalking / bullying / mobbing (group bullying or gang stalking)
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
* Call a person other name than that declared by the person
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the Pragmatismo security team at c. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] and ICAPS Code of Conduct.
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

View file

@ -22,19 +22,17 @@ When logging a bug, please be sure to include the following:
We also accept suggestions in the issue tracker. We also accept suggestions in the issue tracker.
In general, things we find useful when reviewing suggestions are: In general, things we find useful when reviewing suggestions are:
* A description of the problem you're trying to solve * A description of the problem you're trying to solve
* An overview of the suggested solution * An overview of the suggested solution
* Examples of how the suggestion would work in various places * Examples of how the suggestion would work in various places
# Instructions for Contributing Code # Instructions for Contributing Code
## Contributing bug fixes ## Contributing bug fixes
General Bots is current in early preview. We're still accepting contributions in the form of bug fixes. General Bots is current in early preview. We're still accepting contributions in the form of bug fixes.
A bug must have an issue tracking it in the issue tracker that has been approved by the Pragmatismo.io team. Your pull request should include a link to the bug that you are fixing. If you've submitted a PR for a bug, please post a comment in the bug to avoid duplication of effort. A bug must have an issue tracking it in the issue tracker that has been approved by the pragmatismo.cloud team. Your pull request should include a link to the bug that you are fixing. If you've submitted a PR for a bug, please post a comment in the bug to avoid duplication of effort.
## Contributing features ## Contributing features
@ -42,7 +40,7 @@ Please open an issue with the `Schema` label to get a discussion started.
## Legal ## Legal
We appreciate community contributions to code repositories open sourced by Pragmatismo.io. By signing a contributor license agreement, we ensure that the community is free to use your contributions. We appreciate community contributions to code repositories open sourced by pragmatismo.cloud. By signing a contributor license agreement, we ensure that the community is free to use your contributions.
## Housekeeping ## Housekeeping
@ -54,6 +52,33 @@ Your pull request should:
* Have clear commit messages * Have clear commit messages
* e.g. "Refactor feature", "Fix issue", "Add tests for issue" * e.g. "Refactor feature", "Fix issue", "Add tests for issue"
## Running (and adding) the Tests ## You need to be able to run your system
from: http://catern.com/run.html
When developing a system, it is important to be able to run the system in its entirety.
"Run the unit tests" doesn't count. The complexity of your system is in the interactions between the units.
"Run an individual service against mocks" doesn't count. A mock will rarely behave identically to the real dependency, and the behavior of the individual service will be unrealistic. You need to run the actual system.
"Run an individual service in a shared stateful development environment running all the other services" doesn't count. A shared development environment will be unreliable as it diverges more and more from the real system.
"Run most services in a mostly-isolated development environment, calling out to a few hard-to-run external services" doesn't count. Those few external services on the edge of the mostly-isolated development environment are often the most crucial ones; without the ability to run modified versions of them, your development process is crippled. Furthermore, being dependent on external services greatly complicates where and how you can run the system; it's much harder to, for example, run tests with the system on every commit if that will access external services.
"Run all the services that make up the system in an isolated development environment" counts; it's the bare minimum requirement. Bonus points if this can be done completely on localhost, without using an off-host cluster deployment system.
Without the ability to actually run the entire system in this way while developing, many evil practices will tend to become common.
Testing is harder and far less representative, and therefore many issues can only be found when changes are deployed to production.
In turn, production deployment will cause issues more often, and so deployment will be more slow and less frequent.
Deploying the system to new environments is more difficult, since the developers aren't able to actually run the system. Existing practices in production will be cargo-culted and copied around indefinitely, even when they are unnecessary or actively harmful.
Exploratory usage of the system is very difficult, so it will be harder to consider using the system for purposes outside what it was originally developed for, and new use cases will become rare.
Downstream clients who depend on the system will also suffer all these issues, since without the ability to run the upstream system in development, they can't run their own entire system, which is a superset of the upstream system.
Running the entire system during development is the first step to preventing these issues. Further steps include writing automated tests for the system (which can be run repeatedly during development), and using, as much as possible, the same code to run the system in development and in production.
Developers of large or legacy systems that cannot already be run in their entirety during development often believe that it is impractical to run the entire system during development. They'll talk about the many dependencies of their system, how it requires careful configuration of a large number of hosts, or how it's too complex to get reliable behavior.
In my experience, they're always wrong. These systems can be run locally during development with a relatively small investment of effort. Typically, these systems are just ultimately not as complicated as people think they are; once the system's dependencies are actually known and understood rather than being cargo-culted or assumed, running the system, and all its dependencies, is straightforward.
Being able to run your entire system during development is just about the most basic requirement for a software project. It's not, on its own, sufficient for your development practices to be high quality; but if you can't do this, then you're not even in the running.
*Coming soon*

148
DATABASE-CHANGES.md Normal file
View file

@ -0,0 +1,148 @@
# 2.0.0
``` SQL
ALTER TABLE dbo.GuaribasUser ADD
agentSystemId nvarchar(16) NULL,
agentMode nvarchar(16) NULL,
agentContacted datetime NULL
GO
ALTER TABLE [dbo].[GuaribasUser] DROP COLUMN [phone]
GO
ALTER TABLE [dbo].[GuaribasUser] DROP COLUMN [internalAddress]
GO
ALTER TABLE [dbo].[GuaribasUser] DROP COLUMN [currentBotId]
GO
ALTER TABLE [dbo].[GuaribasInstance] DROP COLUMN [authenticatorClientId]
GO
ALTER TABLE [dbo].[GuaribasInstance] DROP COLUMN [authenticatorClientSecret]
GO
ALTER TABLE dbo.GuaribasUser ADD
locale nvarchar(5) NULL
GO
ALTER TABLE dbo.GuaribasInstance ADD
translatorKey nvarchar(64) NULL
translatorEndpoint nvarchar(64) NULL
GO
ALTER TABLE dbo.GuaribasInstance ADD
activationCode nvarchar(16) NULL
GO
ALTER TABLE dbo.GuaribasInstance ADD
params nvarchar(4000) NULL
GO
ALTER TABLE dbo.GuaribasInstance ADD
state nvarchar(16) NULL
GO
UPDATE dbo.GuaribasInstance SET state= 'active'
# 2.0.3
``` SQL
ALTER TABLE dbo.GuaribasPackage ADD
params custom(512) NULL
GO
```
# 2.0.56
ALTER TABLE dbo.GuaribasUser ADD
hearOnDialog nvarchar(64) NULL
GO
ALTER TABLE dbo.GuaribasConversation ADD
instanceId int,
feedback nvarchar(512) NULL
GO
ALTER TABLE [dbo].[GuaribasInstance] DROP COLUMN [translatorendpoint]
GO
ALTER TABLE dbo.GuaribasInstance ADD
translatorEndpoint nvarchar(128) NULL
GO
# 2.0.108
ALTER TABLE [dbo].[GuaribasInstance] DROP COLUMN [agentSystemId]
GO
ALTER TABLE dbo.GuaribasUser ADD
agentSystemId nvarchar(255) NULL,
GO
# 2.0.115
ALTER TABLE dbo.GuaribasQuestion ADD
skipIndex bit NULL
GO
# 2.0.116 >
ALTER TABLE dbo.GuaribasInstance ADD
googleBotKey nvarchar(255) NULL,
googleChatApiKey nvarchar(255) NULL,
googleChatSubscriptionName nvarchar(255) NULL,
googleClientEmail nvarchar(255) NULL,
googlePrivateKey nvarchar(4000) NULL,
googleProjectId nvarchar(255) NULL
GO
# 2.0.119
ALTER TABLE dbo.GuaribasInstance ADD
facebookWorkplaceVerifyToken nvarchar(255) NULL,
facebookWorkplaceAppSecret nvarchar(255) NULL,
facebookWorkplaceAccessToken nvarchar(512) NULL
GO
# 2.0.140
/****** Object: Table [dbo].[GuaribasSchedule] Script Date: 25/08/2021 03:53:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[GuaribasSchedule]
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](255) NULL,
[schedule] [nvarchar](255) NULL,
[instanceId] [int] NULL,
[createdAt] [datetimeoffset](7) NULL,
[updatedAt] [datetimeoffset](7) NULL
GO
ALTER TABLE dbo.GuaribasInstance ADD botKey nvarchar(64) NULL;
# 2.3.9
GO
ALTER TABLE dbo.GuaribasUser ADD
params nvarchar(4000) NULL
GO

8
FEATURES.md Normal file
View file

@ -0,0 +1,8 @@
# General Bots Features
| Feature | BF | GB |
|----------------------------------------------------------------------------|----|----|
| Use of conversational administration to manage bot packages (Talk to admin)| - | X |
| F5 to run on VSCode | - | X |
| Isolated code on packages | - | X |
| Breaking changes protected | - | X |

View file

@ -1,5 +1,5 @@
General Bots is licensed under a dual license. To check which license General Bots is licensed under a dual license. To check which license
edition of General bots you have installed, please ask info@pragmatismo.io edition of General bots you have installed, please ask info@pragmatismo.cloud
informing your Customer ID. informing your Customer ID.
If you modify this Program, or any covered work, by combining it If you modify this Program, or any covered work, by combining it

7
LOCALIZATION.md Normal file
View file

@ -0,0 +1,7 @@
# Localization in General Bots
## .gbapp
The localization is done by adding a strings.ts file to the root of the .gbapp package.

208
README.md
View file

@ -1,142 +1,100 @@
General Bots Community Edition Preview <a href="https://github.com/generalbots/botserver/graphs/contributors">
==================================== <img src="https://contrib.rocks/image?repo=generalbots/botserver" />
</a>
Welcome to General Bots!
-------
General Bots is a packaged based chat bot server focused in convention | Area | Status |
over configuration and codeless aproaches, which brings software packages |------------------------------|----------------------------------------------------------------------------------------------------|
and application server concepts to help parallel bot development. | Releases | [![General Bots](https://img.shields.io/npm/dt/botserver.svg?logo=npm&label=botserver)](https://www.npmjs.com/package/botserver/) [![.gbapp lib](https://img.shields.io/npm/dt/botlib.svg?logo=npm&label=botlib)](https://www.npmjs.com/package/botlib/) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)|
| Community | [![StackExchange](https://img.shields.io/stackexchange/stackoverflow/t/generalbots.svg)](https://stackoverflow.com/questions/tagged/generalbots) [![Open-source](https://badges.frapsoft.com/os/v2/open-source.svg)](https://badges.frapsoft.com) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) [![License](https://img.shields.io/badge/license-AGPL-blue.svg)](https://github.com/GeneralBots/BotServer/blob/master/LICENSE.txt)|
| Management | [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://gitHub.com/GeneralBots/BotServer/graphs/commit-activity) |
| Security | [![Known Vulnerabilities](https://snyk.io/test/github/GeneralBots/BotServer/badge.svg)](https://snyk.io/test/github/GeneralBots/BotServer) |
| Building & Quality | [![Build Status](https://travis-ci.com/GeneralBots/BotServer.svg?branch=master)](https://app.travis-ci.com/github/GeneralBots/BotServer) [![Coverage Status](https://coveralls.io/repos/github/GeneralBots/BotServer/badge.svg)](https://coveralls.io/github/GeneralBots/BotServer) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) |
| Packaging | [![forthebadge](https://badge.fury.io/js/botserver.svg)](https://badge.fury.io) [![ZipFile](https://camo.githubusercontent.com/0150c0f148d50fe9750ebc5d313581da699a8c50/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7a69702d646f776e6c6f61642d626c75652e737667)](https://github.com/GeneralBots/BotServer/releases/latest) [![Dependencies](https://david-dm.org/GeneralBots/botserver.svg)](https://david-dm.org) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) |
| Samples | [VBA](https://github.com/GeneralBots/BotServer/tree/master/packages/default.gbdialog) or [![TypeScript](https://badges.frapsoft.com/typescript/code/typescript.svg?v=101)](https://github.com/GeneralBots/AzureADPasswordReset.gbapp)
| [Docker Image](https://github.com/lpicanco/docker-botserver) | ![Docker Automated build](https://img.shields.io/docker/automated/lpicanco/botserver.svg) ![Docker Build Status](https://img.shields.io/docker/build/lpicanco/botserver.svg) ![MicroBadger Size](https://img.shields.io/microbadger/image-size/lpicanco/botserver.svg) ![MicroBadger Layers](https://img.shields.io/microbadger/layers/lpicanco/botserver.svg) ![Docker Pulls](https://img.shields.io/docker/pulls/lpicanco/botserver.svg) <br/> *Provided by [@lpicanco](https://github.com/lpicanco/docker-botserver)* |
Also, everyone can create bots copying and pasting some files and using their General Bots
favorite tools like Excel (or any .tsv editor) or Photoshop (or any .png ------------------
editor).
### What is Bot Server? ![General Bot Logo](https://raw.githubusercontent.com/pragmatismo-io/BotServer/master/logo.png)
General Bot is a strongly typed package based chat bot server focused in convention over configuration and code-less approaches, which brings software packages and application server concepts to help parallel bot development.
## What is a Bot Server?
Bot Server accelerates the process of developing a bot. It provisions all code Bot Server accelerates the process of developing a bot. It provisions all code
base, resources and deployment to the cloud, and gives you templates you can base, resources and deployment to the cloud, and gives you templates you can
choose from when you create a bot. Uses a database and tables as backend and choose from whenever you need a new bot. The server has a database and service
allow you to further modify your bot package directly downloading it in a ZIP backend allowing you to further modify your bot package directly by downloading
file and editing it and uploading it back to the server (deploying process). a zip file, editing and uploading it back to the server (deploying process) with
Besides providing a framework to develop bot packages in a more advanced no code. The Bot Server also provides a framework to develop bot packages in a more
editor like Visual Studio Code, Atom or Brackets. advanced fashion writing custom code in editors like Visual Studio Code, Atom or Brackets.
### The same build process for everyone Everyone can create bots by just copying and pasting some files and using their
favorite tools from Office (or any text editor) or Photoshop (or any image
editor). BASIC can be used to build custom dialogs so Bot can be extended just like VBA for Excel (currently in alpha).
GeneralBots aims to delivery bots in azure in a very easy and fast fashion. Use ![General Bot Reference Architecture](https://raw.githubusercontent.com/GeneralBots/BotBook/master/images/general-bots-reference-architecture.png)
Office tools like Word or Excel to edit your Bot - using code (JavaScript or TypeScript) just to empower custom requirements.
How To ## Samples
------
Several samples, including a Bot for AD Password Reset, are avaiable on the [repository list](https://github.com/GeneralBots).
### Using complete General Bots Conversational Data Analytics
![](https://user-images.githubusercontent.com/14840374/178154826-8188029e-b4f4-48aa-bc0d-126307ce5121.png)
```
TALK "General Bots Labs presents FISCAL DATA SHOW BY BASIC"
TALK "Gift Contributions to Reduce the Public Debt API (https://fiscaldata.treasury.gov/datasets/gift-contributions-reduce-debt-held-by-public/gift-contributions-to-reduce-the-public-debt)"
result = GET "https://api.fiscaldata.treasury.gov/services/api/fiscal_service/v2/accounting/od/gift_contributions?page[size]=500"
data = result.data
data = SELECT YEAR(record_date) as Yr, SUM(CAST(contribution_amt AS NUMBER)) AS Amount FROM data GROUP BY YEAR(record_date)
TALK "Demonstration of Gift Contributions with AS IMAGE keyword"
SET THEME dark
png = data as IMAGE
SEND FILE png
DELAY 5
TALK " Demonstration of Gift Contributions CHART keyword"
img = CHART "bar", data
SEND FILE img
```
## Guide
[Read the General Bots BotBook Guide](https://github.com/GeneralBots/BotBook/tree/master/book).
# Videos
Now with the General Bots server you can press F5 on Visual Studio to get a bot factory on your environment* published on November 10th, 2018.
[![General Bot Video](https://raw.githubusercontent.com/pragmatismo-io/BotServer/master/docs/images/video-01-thumb.jpg)](https://www.youtube.com/watch?v=AfKTwljoMOs)
See how easy is to use 'hear' and 'talk' to build Microsoft BOT Framework v4 logic with plain BASIC * published on December 3rd, 2018.
[![See how easy is to use 'hear' and 'talk' to build Microsoft BOT Framework v4 logic with plain BASIC](https://raw.githubusercontent.com/pragmatismo-io/BotServer/master/docs/images/video-02-thumb.jpg)](https://www.youtube.com/watch?v=yX1sF9n9628)
### Updating the Bot Knoledge Base (.gbkb folder) # Contributing
This project welcomes contributions and suggestions.
See our [Contribution Guidelines](https://github.com/pragmatismo-io/BotServer/blob/master/CONTRIBUTING.md) for more details.
The subjects.json file contains all information related to the subject tree and can be used to build the menu carrousel as well give a set of words to be used as subject catcher in the conversation. A hierarchy can be specified. # Reporting Security Issues
Security issues and bugs should be reported privately, via email, to the pragmatismo.cloud Security
team at [security@pragmatismo.cloud](mailto:security@pragmatismo.cloud). You should
receive a response within 24 hours. If for some reason you do not, please follow up via
email to ensure we received your original message.
### Creating a new Theme folder (.gbtheme folder) # License & Warranty
A theme is composed of some CSS files and images. That set of files can change General Bot Copyright (c) pragmatismo.cloud. All rights reserved.
everything in the General Bots UI. Use them extensively before going to change
the UI application itself (HTML & JS).
Package Types
-------------
### .gbai
Embraces all packages types (content, logic & conversation) into a pluggable bot
directory.
### .gbapp
The artificial intelligence extensions in form of pluggable apps. Dialogs,
Services and all model related to data. A set of interactions, use cases,
integrations in form of conversationals dialogs.
The .gbapp adds the General Bots base library (botlib) for building Node.js TypeScript Apps packages.
Four components builds up a General Bots App:
* dialogs
* models
* services
* tests
#### Dialogs
All code contained in a dialog builds the flow to custom conversations in
built-in and additional packages .
#### Models
Models builds the foundation of data relationships in form of entities.
#### Services
Services are a façade for bot back-end logic and other custom processing.
#### Tests
Tests try to automate code execution validation before crashing in production.
### .gbot
An expression of an artificial inteligence entity. A .gbot file defines
all bots dependencies related to services and other resources.
### .gbtheme
A theme of a bot at a given time. CSS files & images that can compose all UI
presentation and using it a branding can be done.
### .gbkb
A set of subjects that bot knows.
### .gblib
Shared code that can be used across bot apps.
Reference
---------
### GeneralBots admin commands
General Bots can be controlled by the same chat window people talk to, so
here is a list of admin commands related to deploying .gb* files.
| Command | Description |
|-----------------|-----------------------------------------------------------------------------------------------------------------|
| deployPackage | Deploy a KB package. Usage **deployPackage** [package-name]. Then, you need to run rebuildIndex. |
| undeployPackage | Undeploy a KB. Usage **undeployPackage** [package-name]. |
| redeployPackage | Undeploy and then deploys the KB. Usage **redeployPackage** [package-name]. Then, you need to run rebuildIndex. |
| rebuildIndex | Rebuild Azure Search indexes, must be run after **deployPackage** or **redeployPackage**. |
### Credits & Inspiration
* Rodrigo Rodriguez (me@rodrigorodriguez.com) - Coding, Docs & Architecture.
* David Lerner (david.lerner@hotmail.com) - UI, UX & Theming
* Eduardo Romeiro (eromeirosp@outlook.com) - Content & UX
Powered by Microsoft [BOT Framework](https://dev.botframework.com/) and [Azure](http://www.azure.com).
General Bots Code Name is [Guaribas](https://en.wikipedia.org/wiki/Guaribas), the name of a city in Brazil, state of Piaui.
[Roberto Mangabeira Unger](http://www.robertounger.com/en/): "No one should have to do work that can be done by a machine".
## License & Warranty
General Bots Copyright (c) Pragmatismo.io. All rights reserved.
Licensed under the AGPL-3.0. Licensed under the AGPL-3.0.
According to our dual licensing model, this program can be used either According to our dual licensing model, this program can be used either
@ -152,8 +110,12 @@ General Bots Code Name is [Guaribas](https://en.wikipedia.org/wiki/Guaribas), th
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. GNU Affero General Public License for more details.
"General Bots" is a registered trademark of Pragmatismo.io. "General Bot" is a registered trademark of pragmatismo.cloud.
The licensing of the program under the AGPLv3 does not imply a The licensing of the program under the AGPLv3 does not imply a
trademark license. Therefore any rights, title and interest in trademark license. Therefore any rights, title and interest in
our trademarks remain entirely with us. our trademarks remain entirely with us.
<a href="https://stackoverflow.com/questions/ask?tags=generalbots">:speech_balloon: Ask a question</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://github.com/GeneralBots/BotBook">:book: Read the Docs</a>
Team pictures made with [contrib.rocks](https://contrib.rocks).
General Bots Code Name is [Guaribas](https://en.wikipedia.org/wiki/Guaribas), the name of a city in Brazil, state of Piaui.
[Roberto Mangabeira Unger](http://www.robertounger.com/en/): "No one should have to do work that can be done by a machine".

6
ROADMAP.md Normal file
View file

@ -0,0 +1,6 @@
# Roadmap
| Title | Priority | Release | Status |
|-------------------------------|------------------------------------------------------------------------------------------------------------|---------|--------|
| Isolation of .gbapp per .gbot | Today .gbapp loaded is shared across all bot instances and must be associated to one or more individually. | Medium | 2019Q4 |
| Python based .gbapps | Write conversational login in Python | Low | - |

7
SAMPLES.md Normal file
View file

@ -0,0 +1,7 @@
# General Bots Server Samples
| Sample | Description |
|--------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
| [IntranetBotQuickStart-gbai](https://github.com/pragmatismo-io/IntranetBotQuickStart.gbai) | Free modules from General Bots Intranet based bot. |
| [AzureADPasswordReset-gbapp](https://github.com/pragmatismo-io/AzureADPasswordReset.gbapp) | Custom General Bot App (gbapp) for resetting an user password in Azure Active Directory, Office 365, Dynamics 365 or any app published through Azure AD. |
| [ProjectOnline.gbkb](https://github.com/pragmatismo-io/ProjectOnline.gbkb) | The .gbkb file demonstring a Knowledge Base for pragmatismo.cloud KBot for Microsoft Project. |

61
SECURITY.md Normal file
View file

@ -0,0 +1,61 @@
# General Bots Security Policy
## Overview
Request your free IT security evaluation
• Reduce the risk of IT problems
• Plan for problems and deal with them when they happen
• Keep working if something does go wrong
• Protect company, client and employee data
• Keep valuable company information, such as plans and designs, secret
• Meet our legal obligations under the General Data Protection Regulation and other laws
• Meet our professional obligations towards our clients and customers
This IT security policy helps us:
• Rodrigo Rodriguez is the director with overall responsibility for IT security strategy.
• Microsoft is the IT partner organisation we use to help with our planning and support.
• Microsoft is the data protection officer to advise on data protection laws and best practices
Review process
We will review this policy yearly.
In the meantime, if you have any questions, suggestions
or feedback, please contact security@pragmatismo.cloud
We will only classify information which is necessary for the completion of our duties. We will also limit
access to personal data to only those that need it for processing. We classify information into different
categories so that we can ensure that it is protected properly and that we allocate security resources
appropriately:
• Unclassified. This is information that can be made public without any implications for the company,
such as information that is already in the public domain.
• Employee confidential. This includes information such as medical records, pay and so on.
• Company confidential. Such as contracts, source code, business plans, passwords for critical IT
systems, client contact records, accounts etc.
• Client confidential. This includes personally identifiable information such as name or address,
passwords to client systems, client business plans, new product information, market sensitive
information etc.
Employees joining and leaving
We will provide training to new staff and support for existing staff to implement this policy. This includes:
• An initial introduction to IT security, covering the risks, basic security measures, company policies
and where to get help
• Each employee will complete the National Archives Responsible for Information training course
(approximately 75 minutes)
• Training on how to use company systems and security software properly
• On request, a security health check on their computer, tablet or phone
When people leave a project or leave the company, we will promptly revoke their access privileges to
The company will ensure the data protection office is given all appropriate resources to carry out their
tasks and maintain their expert knowledge.
The Data Protection Officer reports directly to the highest level of management and must not carry out
any other tasks that could result in a conflict of interest.
## Reporting a Vulnerability
You can expect to get an update on a reported vulnerability in a day or two.
security@pragmatismo.cloud

79
WARNINGS.md Normal file
View file

@ -0,0 +1,79 @@
# default.gbui
https://github.com/microsoft/BotFramework-WebChat/pull/4524
warning botframework-directlinejs > core-js@3.15.2: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
warning botframework-webchat > botframework-webchat-component > @emotion/css > @emotion/babel-plugin > @babel/plugin-syntax-jsx@7.18.6" has unmet peer dependency "@babel/core@^7.0.0-0".
warning botframework-webchat > botframework-webchat-component > @emotion/css > @emotion/babel-plugin@11.10.5" has unmet peer dependency "@babel/core@^7.0.0".
warning botframework-webchat > botframework-webchat-component > react-film > core-js@3.12.1: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
warning botframework-webchat > botframework-webchat-component > react-scroll-to-bottom > core-js@3.18.3: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
warning botframework-webchat > botframework-webchat-core > redux-devtools-extension@2.13.9: Package moved to @redux-devtools/extension.
warning botframework-webchat > microsoft-cognitiveservices-speech-sdk > asn1.js-rfc2560@5.0.1" has unmet peer dependency "asn1.js@^5.0.0".
warning botframework-webchat > web-speech-cognitive-services@7.1.2" has incorrect peer dependency "microsoft-cognitiveservices-speech-sdk@~1.17.0".
https://github.com/microsoft/powerbi-client-react
warning react-powerbi@0.9.1" has incorrect peer dependency "react@^16.8.0".
warning react-scripts > @svgr/webpack > @svgr/plugin-svgo > svgo > stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
warning react-scripts > @svgr/webpack > @svgr/plugin-svgo > svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
warning react-scripts > css-minimizer-webpack-plugin > cssnano > cssnano-preset-default > postcss-svgo > svgo > stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
warning react-scripts > eslint-config-react-app > @typescript-eslint/eslint-plugin > tsutils@3.21.0" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
warning react-scripts > eslint-config-react-app > eslint-plugin-flowtype@8.0.3" has unmet peer dependency "@babel/plugin-syntax-flow@^7.14.5".
warning react-scripts > eslint-config-react-app > eslint-plugin-flowtype@8.0.3" has unmet peer dependency "@babel/plugin-transform-react-jsx@^7.14.9".
warning react-scripts > jest > @jest/core > jest-config > jest-environment-jsdom > jsdom > w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin.
warning react-scripts > react-dev-utils > fork-ts-checker-webpack-plugin@6.5.2" has unmet peer dependency "typescript@>= 2.7".
# BotServer
docxtemplater is not working in more modern versions. Stay with 3.9.7.
nodejs/node-gyp#2756
warning npm > node-gyp > make-fetch-happen > cacache > @npmcli/move-file@2.0.1: This functionality has been moved to @npmcli/fs
vasyas/typescript-rest-rpc#20
warning typescript-rest-rpc > ts-morph > globby > fast-glob > micromatch > snapdragon > source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
#279
warning tslint@6.1.3: TSLint has been deprecated in favor of ESLint. Please see palantir/tslint#4534 for more information.
AlaSQL/alasql#1541
warning alasql > request@2.88.2: request has been deprecated, see request/request#3142
#281
warning c3-chart-maker > data-forge > promised-mongo > mongodb-core > bson@0.4.23: Fixed a critical issue with BSON serialization documented in CVE-2019-2391, see https://bit.ly/2KcpXdo for more details
#280
warning swagger-client > url > querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
bahmutov/ggit#157
warning ban-sensitive-files > ggit > debug@3.2.6: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (debug-js/debug#797)
#283
warning nexmo > uuid@2.0.3: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
https://github.com/microsoft/botbuilder-js/issues/4370
warning botbuilder-ai > @azure/cognitiveservices-luis-runtime > @azure/ms-rest-js > uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
https://github.com/Azure/azure-sdk-for-node/issues/5221
warning ms-rest-azure > request@2.88.2: request has been deprecated, see request/request#3142
https://github.com/MontassarLaribi/ssr-for-bots/issues/1
warning ssr-for-bots > tslint@6.1.3: TSLint has been deprecated in favor of ESLint. Please see palantir/tslint#4534 for more information.
https://github.com/vasyas/typescript-rest-rpc/issues/20
warning typescript-rest-rpc > ts-morph > globby > fast-glob > micromatch > snapdragon > source-map-resolve > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
https://github.com/ash-developer/winston-logs-display/issues/8
warning winston-logs-display > jade > transformers@2.1.0: Deprecated, use jstransformer
https://github.com/softwarescales/git-issues/issues/29
warning git-issues > request@2.88.2: request has been deprecated, see request/request#3142
https://github.com/GeneralBots/BotServer/issues/284
warning license-checker > read-installed > readdir-scoped-modules@1.1.0: This functionality has been moved to @npmcli/fs
https://github.com/semantic-release/semantic-release/issues/1260
warning semantic-release > @semantic-release/npm > npm > readdir-scoped-modules@1.1.0: This functionality has been moved to @npmcli/fs
https://github.com/GeneralBots/BotServer/issues/277
warning travis-deploy-once@3.3.0: We recommend to use Travis Build Stages instead

14
api-template.json Normal file
View file

@ -0,0 +1,14 @@
{
"openapi": "3.0.0",
"info": {
"title": "General Bots API",
"description": "General Bots API description in Swagger format",
"version": "1.0"
},
"servers": [
{
"url": "https://gb.pragmatismo.cloud/api",
"description": "General Bots Online"
}
]
}

BIN
blank.docx Normal file

Binary file not shown.

BIN
blank.xlsx Normal file

Binary file not shown.

55
boot.mjs Normal file
View file

@ -0,0 +1,55 @@
#!/usr/bin/env node
import Fs from 'fs';
import os from 'node:os';
import Path from 'path';
import { exec } from 'child_process';
import pjson from './package.json' assert { type: 'json' };
// Displays version of Node JS being used at runtime and others attributes.
process.stdout.write(`General Bots. BotServer@${pjson.version}, botlib@${pjson.dependencies.botlib}, botbuilder@${pjson.dependencies.botbuilder}, node@${process.version.replace('v', '')}, ${process.platform} ${process.arch} `);
console.log(`\nLoading virtual machine source code files...`);
var __dirname = process.env.PWD || process.cwd();
try {
var run = () => {
import('./dist/src/app.js').then((gb)=> {
gb.GBServer.run()
});
};
var processDist = () => {
if (!Fs.existsSync('dist')) {
console.log(`\n`);
console.log(`Generall Bots: Compiling...`);
exec(Path.join(__dirname, 'node_modules/.bin/tsc'), (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
run();
});
} else {
run();
}
};
// Installing modules if it has not been done yet.
if (!Fs.existsSync('node_modules')) {
console.log(`\n`);
console.log(`Generall Bots: Installing modules for the first time, please wait...`);
exec('npm install', (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
processDist();
});
} else {
processDist();
}
} catch (e) {
console.log(e);
}

View file

@ -96,7 +96,7 @@ call :SelectNodeVersion
:: 3. Install npm packages :: 3. Install npm packages
IF EXIST "%DEPLOYMENT_TARGET%\package.json" ( IF EXIST "%DEPLOYMENT_TARGET%\package.json" (
pushd "%DEPLOYMENT_TARGET%" pushd "%DEPLOYMENT_TARGET%"
echo GUARIBASDEPLOYER ------------------ Installing packages for server. echo [General Bots Deployer] Installing packages for server...
call :ExecuteCmd !NPM_CMD! install --production call :ExecuteCmd !NPM_CMD! install --production
IF !ERRORLEVEL! NEQ 0 goto error IF !ERRORLEVEL! NEQ 0 goto error
popd popd
@ -104,20 +104,24 @@ IF EXIST "%DEPLOYMENT_TARGET%\package.json" (
:: 3.1 Install npm packages on UI :: 3.1 Install npm packages on UI
IF EXIST "%DEPLOYMENT_TARGET%\deploy\default.gbui\package.json" ( IF EXIST "%DEPLOYMENT_TARGET%\deploy\default.gbui\package.json" (
call :ExecuteCmd !NPM_CMD! config set scripts-prepend-node-path true
pushd "%DEPLOYMENT_TARGET%\deploy\default.gbui" pushd "%DEPLOYMENT_TARGET%\deploy\default.gbui"
echo GUARIBASDEPLOYER ------------------ Installing packages for default.gbui. echo [General Bots Deployer] Installing packages for default.gbui...
call :ExecuteCmd !NPM_CMD! install call :ExecuteCmd !NPM_CMD! install
echo GUARIBASDEPLOYER ------------------ Building default.gbui. echo [General Bots Deployer] Building default.gbui...
call :ExecuteCmd !NPM_CMD! run build call :ExecuteCmd !NPM_CMD! run build
IF !ERRORLEVEL! NEQ 0 goto error IF !ERRORLEVEL! NEQ 0 goto error
RMDIR /s /q "%DEPLOYMENT_TARGET%\deploy\default.gbui\node_modules"
popd popd
) )
:: 4. Install TypeScript
:: 4. Install typescript echo [General Bots Deployer] Transpiling...
echo GUARIBASDEPLOYER ------------------ Transpiling... call :ExecuteCmd node %DEPLOYMENT_TARGET%\node_modules\typescript\bin\tsc -v
call :ExecuteCmd node %DEPLOYMENT_TARGET%\node_modules\typescript\bin\tsc -p "%DEPLOYMENT_TARGET%" call :ExecuteCmd node %DEPLOYMENT_TARGET%\node_modules\typescript\bin\tsc -p "%DEPLOYMENT_TARGET%"
echo [General Bots Deployer] Deployment Finished.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
goto end goto end

96
deploy.sh Normal file
View file

@ -0,0 +1,96 @@
#!/bin/bash
# ------------------------
# General Bots deployment.
# ------------------------
# Helpers
# -------
exitWithMessageOnError () {
if [ ! $? -eq 0 ]; then
echo "[General Bots Deployer]An error has occurred during web site deployment."
echo $1
exit 1
fi
}
# Prerequisites
# -------------
# Verify node.js installed
hash node 2>/dev/null
exitWithMessageOnError "Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment."
# Setup
# -----
SCRIPT_DIR="${BASH_SOURCE[0]%\\*}"
SCRIPT_DIR="${SCRIPT_DIR%/*}"
ARTIFACTS=$SCRIPT_DIR/../artifacts
KUDU_SYNC_CMD=${KUDU_SYNC_CMD//\"}
if [[ ! -n "$DEPLOYMENT_SOURCE" ]]; then
DEPLOYMENT_SOURCE=$SCRIPT_DIR
fi
if [[ ! -n "$NEXT_MANIFEST_PATH" ]]; then
NEXT_MANIFEST_PATH=$ARTIFACTS/manifest
if [[ ! -n "$PREVIOUS_MANIFEST_PATH" ]]; then
PREVIOUS_MANIFEST_PATH=$NEXT_MANIFEST_PATH
fi
fi
if [[ ! -n "$DEPLOYMENT_TARGET" ]]; then
DEPLOYMENT_TARGET=$ARTIFACTS/wwwroot
else
KUDU_SERVICE=true
fi
if [[ ! -n "$KUDU_SYNC_CMD" ]]; then
# Install kudu sync
echo Installing Kudu Sync
npm install kudusync -g --silent
exitWithMessageOnError "npm failed"
if [[ ! -n "$KUDU_SERVICE" ]]; then
# In case we are running locally this is the correct location of kuduSync
KUDU_SYNC_CMD=kuduSync
else
# In case we are running on kudu service this is the correct location of kuduSync
KUDU_SYNC_CMD=$APPDATA/npm/node_modules/kuduSync/bin/kuduSync
fi
fi
##################################################################################################################################
# Deployment
# ----------
# 1. Install npm packages
if [ -e "$DEPLOYMENT_SOURCE/package.json" ]; then
echo "[General Bots Deployer] Running npm install..."
cd "$DEPLOYMENT_SOURCE"
eval npm install
echo "[General Bots Deployer] OK."
exitWithMessageOnError "npm failed"
cd - > /dev/null
fi
# 2. Install TypeScript
echo "[General Bots Deployer] Transpiling..."
eval ./node_modules/typescript/bin/tsc -v
eval ./node_modules/typescript/bin/tsc -p "$DEPLOYMENT_SOURCE"
echo "[General Bots Deployer] OK."
# 4. KuduSync
if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then
"$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh"
exitWithMessageOnError "Kudu Sync failed"
fi
##################################################################################################################################
echo "[General Bots Deployer] Finished successfully."

View file

@ -1,174 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
import { AzureSearch } from "pragmatismo-io-framework1";
import { Prompts, Session, UniversalBot } from 'botbuilder';
import { GBMinInstance } from "botlib";
import { IGBDialog } from "botlib";
import { GBDeployer } from '../../core.gbapp/services/GBDeployer';
import { GBImporter } from '../../core.gbapp/services/GBImporter';
import { GBConfigService } from '../../core.gbapp/services/GBConfigService';
const UrlJoin = require("url-join");
export class AdminDialog extends IGBDialog {
static setup(bot: UniversalBot, min: GBMinInstance) {
let importer = new GBImporter(min.core);
let deployer = new GBDeployer(min.core, importer);
bot
.dialog("/admin", [
(session: Session, args) => {
Prompts.text(session, "Please, authenticate:");
if (args == undefined || args.firstRun) {
}
},
(session: Session, results) => {
var text = results.response;
if (
!session.privateConversationData.authenticated ||
text === GBConfigService.get("ADMIN_PASS")
) {
session.privateConversationData.authenticated = true;
session.send(
"Welcome to Pragmatismo.io GeneralBots Administration."
);
Prompts.text(session, "Which task do you wanna run now?");
} else {
session.endDialog();
}
},
function(session: Session, results) {
var text = results.response;
if (text === "quit") {
session.privateConversationData.authenticated = false;
session.replaceDialog("/");
} else if (text === "sync") {
min.core.syncDatabaseStructure(() => {});
session.send("Sync started...");
session.replaceDialog("/admin", {
firstRun: false
});
} else if (text.split(" ")[0] === "rebuildIndex") {
AdminDialog.rebuildIndexCommand(min, session, () =>
session.replaceDialog("/admin", {
firstRun: false
})
);
} else if (text.split(" ")[0] === "deployPackage") {
AdminDialog.deployPackageCommand(text, session, deployer, min, () =>
session.replaceDialog("/admin", {
firstRun: false
})
);
} else if (text.split(" ")[0] === "redeployPackage") {
AdminDialog.undeployPackageCommand(text, min,session, () => {
AdminDialog.deployPackageCommand(text, session, deployer, min, () => {
session.send("Redeploy done.");
session.replaceDialog("/admin", {
firstRun: false
});
});
});
} else if (text.split(" ")[0] === "undeployPackage") {
AdminDialog.undeployPackageCommand(text, min, session, () =>
session.replaceDialog("/admin", {
firstRun: false
})
);
} else if (text.split(" ")[0] === "applyPackage") {
session.send("Applying in progress...");
min.core.loadInstance(text.split(" ")[1], (item, err) => {
session.send("Applying done...");
session.replaceDialog("/");
});
session.replaceDialog("/admin", {
firstRun: false
});
}
}
])
.triggerAction({
matches: /^(admin)/i
});
}
static undeployPackageCommand(text: any, min: GBMinInstance, session: Session, cb) {
let packageName = text.split(" ")[1];
let importer = new GBImporter(min.core);
let deployer = new GBDeployer(min.core, importer);
session.send(`Undeploying package ${packageName}...`);
deployer.undeployPackageFromLocalPath(
min.instance,
UrlJoin("deploy", packageName),
(data, err) => {
session.send(`Package ${packageName} undeployed...`);
cb();
}
);
}
static deployPackageCommand(
text: string,
session: Session,
deployer: GBDeployer,
min: GBMinInstance,
cb
) {
let packageName = text.split(" ")[1];
session.send(`Deploying package ${packageName}... (It may take a few seconds)`);
deployer.deployPackageFromLocalPath(
UrlJoin("deploy", packageName),
(data, err) => {
session.send(`Package ${packageName} deployed... Please run rebuildIndex command.`);
}
);
}
static rebuildIndexCommand(min: GBMinInstance, session: Session, cb) {
let search = new AzureSearch(
min.instance.searchKey,
min.instance.searchHost,
min.instance.searchIndex,
min.instance.searchIndexer
);
session.send("Rebuilding index...");
search.rebuildIndex((data, err) => {
session.send("Index rebuilt.");
});
}
}

View file

@ -1,190 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
import { IGBDialog } from "botlib";
import { Prompts, UniversalBot, Session, ListStyle } from "botbuilder";
import UrlJoin from "url-join";
import { GBMinInstance } from "botlib";
var fs = require("fs");
var request = require("request");
var mkdirp = require("mkdirp");
var builder = require("botbuilder");
const logger = require('../base/winston');
export class AskDialog extends IGBDialog {
static setup(bot: UniversalBot, min: GBMinInstance) {
bot.dialog("/attachFile", [
function(session, args, next) {
logger.debug("/attachFile/F1: Start");
if (session.privateConversationData.JWToken === undefined) {
logger.error("/attachFile/F1: Undefined JWToken");
session.endConversation(
"Unable to store your attachments. Sorry for the inconvenience, please try again."
);
} else {
if (session.privateConversationData.userRequest.text.length === 0) {
if (
session.privateConversationData.userRequest.attachments.length ===
1
) {
var txt =
"I received your attachment. Please let me know how should I handle it.";
} else {
var txt =
"I received your attachments. Please let me know how should I handle them.";
}
var msg = new builder.Message(session)
.textFormat("markdown")
.text(txt);
builder.Prompts.text(session, msg);
} else {
next();
}
}
},
function(session, args, next) {
logger.debug("/attachFile/F2: Start");
if (!(args.response === null) && !(args.response === undefined)) {
session.privateConversationData.userRequest.text = args.response;
}
var mkdirName =
"work"
mkdirp(mkdirName, function(err) {
if (err) {
logger.error(
"/attachFile/F2: unable to create folder. Error-> " + err
);
session.endConversation(
"Unable to store your attachments. Sorry for the inconvenience, please try again."
);
} else {
if (!mkdirName.endsWith("/")) {
mkdirName = mkdirName + "/";
}
session.privateConversationData.attachmentsToWrite =
session.privateConversationData.userRequest.attachments.length -
1;
writeFileRequest(session, mkdirName);
}
});
}
]);
function writeFileRequest(session, mkdirName) {
var options = {
url:
session.privateConversationData.userRequest.attachments[
session.privateConversationData.attachmentsToWrite
].contentUrl,
method: "GET",
headers: {
"Content-type":
session.privateConversationData.userRequest.attachments[
session.privateConversationData.attachmentsToWrite
].contentType
}
};
// if (
// session.message.address.channelId === "skype" ||
// session.message.address.channelId === "msteams"
// ) {
// options.headers.Authorization =
// "Bearer " + session.privateConversationData.JWToken;
// }
request(options, function(err, response, body) {
if (err) {
logger.error(err);
} else {
logger.trace(response.statusCode);
var fileName =
session.privateConversationData.userRequest.attachments[
session.privateConversationData.attachmentsToWrite
].name;
if (fs.existsSync(mkdirName + fileName)) {
var fileType = fileName.substr(fileName.lastIndexOf(".")); //e.g. '.pdf'
var fileSubName = fileName.substr(
0,
fileName.length - fileType.length
); //'name' if original fileName is 'name.pdf'
var j = 1;
while (
fs.existsSync(mkdirName + fileSubName + "(" + j + ")" + fileType)
) {
j += 1;
}
fileName = fileSubName + "(" + j + ")" + fileType;
}
session.privateConversationData.userRequest.attachments[
session.privateConversationData.attachmentsToWrite
] = {
name: fileName,
contentUrl: mkdirName,
contentType:
session.privateConversationData.userRequest.attachments[
session.privateConversationData.attachmentsToWrite
].contentType
};
fs.writeFile(
mkdirName + fileName,
body,
{ encoding: "binary" },
function(err) {
//{encoding: 'binary' , flag: 'wx'}
if (err) {
logger.error(
"/attachFile/F2: unable to save file. Error-> " + err
);
session.endConversation(
"Unable to store your attachments. Sorry for the inconvenience, please try again."
);
} else {
session.privateConversationData.attachmentsToWrite -= 1;
if (session.privateConversationData.attachmentsToWrite < 0) {
session.beginDialog("/textRequest");
} else {
writeFileRequest(session, mkdirName);
}
}
}
);
}
});
}
}
}

View file

@ -1,57 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
const UrlJoin = require("url-join");
import { AdminDialog } from './dialogs/AdminDialog';
import { GBMinInstance, IGBPackage } from "botlib";
import { Session } from 'botbuilder';
import { Sequelize } from 'sequelize-typescript';
import { IGBCoreService } from 'botlib';
export class GBAdminPackage implements IGBPackage {
loadPackage(core: IGBCoreService, sequelize: Sequelize): void {
}
unloadPackage(core: IGBCoreService): void {
}
loadBot(min: GBMinInstance): void {
AdminDialog.setup(min.bot, min);
}
unloadBot(min: GBMinInstance): void {
}
onNewSession(min: GBMinInstance, session: Session): void {
}
}

View file

@ -1,146 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
import {
Sequelize,
DataTypes,
DataTypeUUIDv4,
DataTypeDate,
DataTypeDecimal
} from "sequelize";
import {
Table,
Column,
Model,
HasMany,
BelongsTo,
BelongsToMany,
Length,
ForeignKey,
CreatedAt,
UpdatedAt,
DataType,
IsUUID,
PrimaryKey,
AutoIncrement
} from "sequelize-typescript";
import { GuaribasSubject } from "../../kb.gbapp/models";
import { GuaribasUser } from "../../security.gblib/models";
import { GuaribasChannel, GuaribasInstance } from "../../core.gbapp/models/GBModel";
@Table
export class GuaribasConversation extends Model<GuaribasConversation> {
@PrimaryKey
@AutoIncrement
@Column
conversationId: number;
@ForeignKey(() => GuaribasSubject)
@Column
startSubjectId: number;
@BelongsTo(() => GuaribasSubject)
startSubject: GuaribasSubject;
@ForeignKey(() => GuaribasChannel)
@Column
channelId: string;
@Column rateDate: Date;
@Column({
type: DataType.FLOAT
})
@Column
rate: number;
@Column
@CreatedAt
creationDate: Date;
@Column text: string;
@HasMany(() => GuaribasConversationMessage)
conversationMessage: GuaribasConversationMessage[];
@ForeignKey(() => GuaribasUser)
@Column
startedByUserId: number;
@BelongsTo(() => GuaribasUser)
startedBy: GuaribasUser;
}
@Table
export class GuaribasConversationMessage extends Model<GuaribasConversationMessage> {
@PrimaryKey
@AutoIncrement
@Column
conversationMessageId: number;
@ForeignKey(() => GuaribasSubject)
@Column
subjectId: number;
@Column({ type: DataType.TEXT })
content: string;
@Column
@CreatedAt
creationDate: Date;
@Column
@UpdatedAt
updatedOn: Date;
@ForeignKey(() => GuaribasConversation)
@Column
conversationId: number;
@BelongsTo(() => GuaribasConversation)
conversation: GuaribasConversation;
@ForeignKey(() => GuaribasInstance)
@Column
instanceId: number;
@ForeignKey(() => GuaribasUser)
@Column
userId: number;
@BelongsTo(() => GuaribasUser)
user: GuaribasUser;
}

View file

@ -1,67 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
import { GBServiceCallback } from "botlib";
import { GuaribasUser } from "../../security.gblib/models";
import { GuaribasConversation, GuaribasConversationMessage } from "../models";
export class AnalyticsService {
createConversation(
user: GuaribasUser,
cb: GBServiceCallback<GuaribasConversation>
) {
let conversation = new GuaribasConversation();
conversation.startedBy = user;
conversation.startedByUserId = user.userId;
conversation.save().then((value: GuaribasConversation) => {
cb(conversation, null);
});
}
createMessage(
conversation: GuaribasConversation,
user: GuaribasUser,
content: string,
cb: GBServiceCallback<GuaribasConversationMessage>
) {
let message = GuaribasConversationMessage.build();
message.conversation = conversation;
message.user = user;
message.content = content;
message.save().then((value: GuaribasConversationMessage) => {
cb(value, null);
});
}
}

View file

@ -1,75 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
const WaitUntil = require("wait-until");
import UrlJoin from "url-join";
import { GBCoreService } from "../services/GBCoreService";
import { IGBDialog } from "botlib";
import { GBConversationalService } from "../services/GBConversationalService";
import { UniversalBot, Session, Prompts } from "botbuilder";
import { GBMinInstance } from "botlib";
export class WelcomeDialog extends IGBDialog {
static setup(bot: UniversalBot, min: GBMinInstance) {
bot.dialog("/", [
function (session, args, next) {
if (!session.userData.once) {
session.userData.once = true;
var a = new Date();
const date = a.getHours();
var msg =
date < 12 ? "bom dia" : date < 18 ? "boa tarde" : "boa noite";
session.sendTyping();
let msgs = [`Oi, ${msg}..`, `Oi!`, `Olá, ${msg}`, `Olá!`];
session.endDialog(msgs);
}
if (session.message) {
session.replaceDialog("/answer", { query: session.message.text });
return;
}
let userName = session.message.user.name;
let displayName = session.message.user.name;
if (args) {
userName = args.userName;
displayName = args.displayName;
}
}
]);
}
}

View file

@ -1,62 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
import { GBConversationalService } from "./../services/GBConversationalService";
import { GBCoreService } from "../services/GBCoreService";
import { IGBDialog } from "botlib";
import { UniversalBot, Session, Prompts } from "botbuilder";
import UrlJoin from "url-join";
import { GBMinInstance } from "botlib";
export class WhoAmIDialog extends IGBDialog {
static setup(bot: UniversalBot, min: GBMinInstance) {
bot.dialog("/whoAmI", [
function(session, args) {
session.sendTyping();
session.send(`${min.instance.description}`);
if (min.instance.whoAmIVideo){
session.send(`Vou te mostrar um vídeo. Por favor, aguarde...`);
min.conversationalService.sendEvent(session, "play", {
playerType: "video",
data: min.instance.whoAmIVideo.trim()
});
}
session.replaceDialog('/ask', {isReturning: true});
}
]);
}
}

View file

@ -1,71 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
const UrlJoin = require("url-join");
import { GBMinInstance, IGBPackage } from "botlib";
import { Session } from 'botbuilder';
import { WelcomeDialog } from "./dialogs/WelcomeDialog";
import { WhoAmIDialog } from "./dialogs/WhoAmIDialog";
import { IGBCoreService} from "botlib";
import { Sequelize } from "sequelize-typescript";
import { GuaribasInstance, GuaribasException, GuaribasPackage, GuaribasChannel } from "./models/GBModel";
export class GBCorePackage implements IGBPackage {
loadPackage(core: IGBCoreService, sequelize: Sequelize): void {
core.sequelize.addModels([
GuaribasInstance,
GuaribasPackage,
GuaribasChannel,
GuaribasException,
]);
}
unloadPackage(core: IGBCoreService): void {
}
loadBot(min: GBMinInstance): void {
WelcomeDialog.setup(min.bot, min);
WhoAmIDialog.setup(min.bot, min);
}
unloadBot(min: GBMinInstance): void {
}
onNewSession(min: GBMinInstance, session: Session): void {
}
}

View file

@ -1,182 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
import {
Sequelize,
DataTypes,
DataTypeUUIDv4,
DataTypeDate,
DataTypeDecimal
} from "sequelize";
import {
Table,
Column,
Model,
HasMany,
BelongsTo,
BelongsToMany,
Length,
ForeignKey,
CreatedAt,
UpdatedAt,
DataType,
IsUUID,
PrimaryKey,
AutoIncrement
} from "sequelize-typescript";
import { IGBInstance } from "botlib";
@Table
export class GuaribasInstance extends Model<GuaribasInstance> implements IGBInstance {
@Column
whoAmIVideo: string;
@PrimaryKey
@AutoIncrement
@Column
instanceId: number;
@Column botId: string;
@Column title: string;
@Column description: string;
@Column version: string;
@Column enabledAdmin: boolean;
/* Services section on bot.json */
@Column engineName: string;
@Column marketplaceId: string;
@Column textAnalyticsKey: string;
@Column marketplacePassword: string;
@Column webchatKey: string;
@Column theme: string;
@Column ui: string;
@Column kb: string;
@Column
@Column({ type: DataType.STRING(512) })
nlpServerUrl: string;
@Column searchHost: string;
@Column searchKey: string;
@Column searchIndex: string;
@Column searchIndexer: string;
/* Settings section of bot.json */
@Column({
type: DataType.FLOAT
})
nlpVsSearch: number;
@Column({
type: DataType.FLOAT
})
searchScore: number;
@Column({
type: DataType.FLOAT
})
nlpScore: number;
@Column
@CreatedAt
creationDate: Date;
@Column
@UpdatedAt
updatedOn: Date;
}
@Table
export class GuaribasPackage extends Model<GuaribasPackage> {
@PrimaryKey
@AutoIncrement
@Column
packageId: number;
@Column
packageName: string;
@ForeignKey(() => GuaribasInstance)
@Column
instanceId: number;
}
@Table
export class GuaribasChannel extends Model<GuaribasChannel> {
@PrimaryKey
@AutoIncrement
@Column
channelId: number;
@Column title: string;
}
@Table
export class GuaribasException extends Model<GuaribasException> {
@PrimaryKey
@AutoIncrement
@Column
exceptionId: number;
@Column message: string;
@ForeignKey(() => GuaribasInstance)
@Column
instanceId: number;
@Column
@CreatedAt
creationDate: Date;
}

View file

@ -1,93 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
const logger = require("../../../src/logger");
"use strict";
export class GBConfigService {
static init(): any {
try {
require("dotenv-extended").load({
path: ".env",
errorOnMissing: true,
errorOnExtra: false,
overrideProcessEnv: true
});
} catch (e) {
console.error(e.message);
process.exit(3);
}
}
static get(key: string): any {
let value = process.env["container:" + key];
if (!value) {
value = process.env[key];
}
if (!value) {
switch (key) {
case "DATABASE_DIALECT":
value = "sqlite";
break;
case "DATABASE_STORAGE":
value = "./guaribas.sqlite";
break;
case "ADDITIONAL_DEPLOY_PATH":
value = undefined;
break;
case "BOOT_PACKAGE":
value = "none";
break;
case "DEFAULT_AI":
value = undefined;
break;
case "DATABASE_SYNC":
value = "false";
break;
default:
logger.trace(
`Guaribas General Error: Invalid key on .env file: '${key}'`
);
break;
}
}
return value;
}
}

View file

@ -1,120 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
const UrlJoin = require("url-join");
const gBuilder = require("botbuilder");
const logger = require("../../../src/logger");
import { GBConfigService } from "./GBConfigService";
import { GBCoreService } from "./GBCoreService";
import { Session, Message, LuisRecognizer } from "botbuilder";
import { GBService, GBServiceCallback, IGBConversationalService} from "botlib";
import { GBError } from "botlib";
import { GBERROR_TYPE } from "botlib";
import { GBMinInstance } from "botlib";
export class GBConversationalService implements IGBConversationalService{
coreService: GBCoreService;
constructor(coreService: GBCoreService) {
this.coreService = coreService;
}
sendEvent(session: Session, name: string, value: any) {
var msg = new gBuilder.Message();
msg.data.type = "event";
msg.data.name = name;
msg.data.value = value;
session.send(msg);
}
runNLP(
session: Session,
min: GBMinInstance,
text: string,
cb: GBServiceCallback<any>
) {
LuisRecognizer.recognize(
text,
min.instance.nlpServerUrl,
(err, intents, entities) => {
if (err) {
cb(null, new GBError(err, GBERROR_TYPE.nlpGeneralError));
return;
}
if (intents && intents.length > 0) {
var intent = intents[0].intent;
var entity =
entities && entities.length > 0
? entities[0].entity.toUpperCase()
: null;
logger.trace(
"luis: intent: [" + intent + "] entity: [" + entity + "]"
);
// PACKAGE: Send to packages.
if (intent === "Student.CheckAttendance") {
session.replaceDialog("/belagua-check-attendance", {entities: entities});
}
else if(intent === 'User.Authenticate'){
session.replaceDialog("/belagua-user-login", {entities: entities});
}
else if (intent === "PerguntarSobreTermo") {
session.send(
"Vou mostrar um menu para ajudar você a formular sua pergunta..."
);
session.replaceDialog("/menu");
} else if (intent === "ShowSubjectMenu") {
session.replaceDialog("/menu");
} else {
session.sendTyping();
session.send("Desculpe-me, não encontrei nada a respeito...");
}
cb({ intent, entities }, null);
} else {
session.sendTyping();
session.send("Lamento, não achei nada a respeito...");
cb(null, null);
}
}
);
}
}

View file

@ -1,175 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
const Path = require("path");
const Fs = require("fs");
const _ = require("lodash");
const Parse = require("csv-parse");
const Async = require("async");
const UrlJoin = require("url-join");
const Walk = require("fs-walk");
const logger = require("../../../src/logger");
import { Sequelize } from "sequelize-typescript";
import { Promise } from "bluebird";
import { GBConfigService } from "./GBConfigService";
import { DataTypeUUIDv1 } from "sequelize";
import { UniversalBot } from "botbuilder";
import { GBServiceCallback, IGBInstance, IGBCoreService } from 'botlib';
import { GuaribasInstance } from "../models/GBModel";
/**
* Core service layer.
*/
export class GBCoreService implements IGBCoreService {
public sequelize: Sequelize;
/** Dialect used. Tested: mssql and sqlite. */
dialect: string;
constructor() {
this.dialect = GBConfigService.get("DATABASE_DIALECT");
}
/** Get config and connect to storage. */
initDatabase(cb) {
let host = "";
let database = "";
let username = "";
let password = "";
let storage = "";
if (this.dialect === "mssql") {
host = GBConfigService.get("DATABASE_HOST");
database = GBConfigService.get("DATABASE_NAME");
username = GBConfigService.get("DATABASE_USERNAME");
password = GBConfigService.get("DATABASE_PASSWORD");
} else if (this.dialect === "sqlite") {
storage = GBConfigService.get("DATABASE_STORAGE");
}
this.sequelize = new Sequelize({
host: host,
database: database,
username: username,
password: password,
logging: false,
operatorsAliases: false,
dialect: this.dialect,
storage: storage,
dialectOptions: {
encrypt: true
},
pool: {
max: 32,
min: 8,
idle: 40000,
evict: 40000,
acquire: 40000
}
});
// TODO: Packages add model.
if (GBConfigService.get("DATABASE_SYNC") === "true") {
this.syncDatabaseStructure(cb);
} else {
cb();
}
}
/** Calls ORM to sync storage. */
syncDatabaseStructure(cb) {
logger.trace("Syncing database...");
this.sequelize.sync().then(value => {
logger.trace("Database synced.");
cb();
});
}
/**
* Loads all items to start several listeners.
* @param cb Instances loaded or error info.
*/
loadInstances(cb: GBServiceCallback<IGBInstance[]>) {
GuaribasInstance.findAll({})
.then((items: IGBInstance[]) => {
if (!items) items = [];
if (items.length == 0) {
cb([], null);
} else {
cb(items, null);
}
})
.catch(reason => {
if (reason.message.indexOf("no such table: GuaribasInstance") != -1) {
cb([], null);
} else {
cb(null, reason);
logger.trace(`GuaribasServiceError: ${reason}`);
}
});
}
/**
* Loads just one Bot instance.
*/
loadInstance(botId: string, cb: GBServiceCallback<IGBInstance>) {
let options = { where: {} };
if (botId != "[default]") {
options.where = { botId: botId };
}
GuaribasInstance.findOne(options)
.then((instance: IGBInstance) => {
if (instance) {
cb(instance, null);
} else {
cb(null, null);
}
})
.catch(err => {
cb(null, err);
logger.trace(`GuaribasServiceError: ${err}`);
});
}
}

View file

@ -1,225 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
const logger = require("../../../src/logger");
const Path = require("path");
const Fs = require("fs");
const FsExtra = require("fs-extra");
const _ = require("lodash");
const Async = require("async");
const UrlJoin = require("url-join");
const Walk = require("fs-walk");
const WaitUntil = require("wait-until");
import { KBService } from './../../kb.gbapp/services/KBService';
import { GBImporter } from "./GBImporter";
import { GBCoreService } from "./GBCoreService";
import { GBServiceCallback, IGBCoreService, IGBInstance } from "botlib";
import { Sequelize } from "sequelize-typescript";
import { Promise } from "bluebird";
import { GBConfigService } from "./GBConfigService";
import { DataTypeUUIDv1 } from "sequelize";
import { GBError, GBERROR_TYPE } from "botlib";
import { UniversalBot } from "botbuilder";
import { GBConversationalService } from "./GBConversationalService";
import { GuaribasPackage } from '../models/GBModel';
/** Deployer service for bots, themes, ai and more. */
export class GBDeployer {
core: IGBCoreService;
importer: GBImporter;
workDir: string = "./work";
constructor(core: IGBCoreService, importer: GBImporter) {
this.core = core;
this.importer = importer;
}
/** Deploys a bot to the storage. */
deployBot(localPath: string, cb: GBServiceCallback<any>) {
let packageType = Path.extname(localPath);
let packageName = Path.basename(localPath);
this.importer.importIfNotExistsBotPackage(
packageName,
localPath,
(data, err) => {
if (err) {
logger.trace(err);
} else {
cb(data, null);
}
}
);
}
deployPackageToStorage(
instanceId: number,
packageName: string,
cb: GBServiceCallback<GuaribasPackage>
) {
GuaribasPackage.create({
packageName: packageName,
instanceId: instanceId
}).then((item: GuaribasPackage) => {
cb(item, null);
});
}
deployTheme(localPath: string, cb: GBServiceCallback<any>) {
// DISABLED: Until completed, "/ui/public".
// FsExtra.copy(localPath, this.workDir + packageName)
// .then(() => {
// cb(null, null);
// })
// .catch(err => {
// var gberr = GBError.create(
// `GuaribasBusinessError: Error copying package: ${localPath}.`
// );
// cb(null, gberr);
// });
}
deployPackageFromLocalPath(localPath: string, cb: GBServiceCallback<any>) {
let packageType = Path.extname(localPath);
switch (packageType) {
case ".gbot":
this.deployBot(localPath, cb);
break;
case ".gbtheme":
this.deployTheme(localPath, cb);
break;
// PACKAGE: Put in package logic.
case ".gbkb":
let service = new KBService();
service.deployKb(this.core, this, localPath, cb);
break;
case ".gbui":
break;
default:
var err = GBError.create(
`GuaribasBusinessError: Unknow package type: ${packageType}.`
);
cb(null, err);
break;
}
}
undeployPackageFromLocalPath(
instance: IGBInstance,
localPath: string,
cb: GBServiceCallback<any>
) {
let packageType = Path.extname(localPath);
let packageName = Path.basename(localPath);
this.getPackageByName(instance.instanceId, packageName, (p, err) => {
switch (packageType) {
case ".gbot":
// TODO: this.undeployBot(packageName, localPath, cb);
break;
case ".gbtheme":
// TODO: this.undeployTheme(packageName, localPath, cb);
break;
case ".gbkb":
let service = new KBService();
service.undeployKbFromStorage(instance, p.packageId, cb);
break;
case ".gbui":
break;
default:
var err = GBError.create(
`GuaribasBusinessError: Unknow package type: ${packageType}.`
);
cb(null, err);
break;
}
});
}
getPackageByName(
instanceId: number,
packageName: string,
cb: GBServiceCallback<GuaribasPackage>
) {
var where = { packageName: packageName, instanceId: instanceId };
GuaribasPackage.findOne({
where: where
})
.then((value: GuaribasPackage) => {
cb(value, null);
})
.error(reason => {
cb(null, reason);
});
}
/**
*
* Hot deploy processing.
*
*/
scanBootPackage(cb: GBServiceCallback<boolean>) {
const deployFolder = "deploy";
let bootPackage = GBConfigService.get("BOOT_PACKAGE");
if (bootPackage === "none") {
cb(true, null);
} else {
this.deployPackageFromLocalPath(
UrlJoin(deployFolder, bootPackage),
(data, err) => {
logger.trace(`Boot package deployed: ${bootPackage}`);
if (err) logger.trace(err);
}
);
}
}
}

View file

@ -1,107 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
const _ = require("lodash");
const Parse = require("csv-parse");
const Async = require("async");
const UrlJoin = require("url-join");
const Walk = require("fs-walk");
const logger = require("../../../src/logger");
import { KBService } from './../../kb.gbapp/services/KBService';
import { Sequelize } from "sequelize-typescript";
import { Promise } from "bluebird";
import Fs = require("fs");
import Path = require("path");
import { DataTypeUUIDv1 } from "sequelize";
import { GBConfigService } from "./GBConfigService";
import { GBCoreService } from "./GBCoreService";
import { GBServiceCallback, IGBCoreService, IGBInstance } from "botlib";
import { SecService } from "../../security.gblib/services/SecService";
import { GuaribasInstance } from "../models/GBModel";
export class GBImporter {
core: IGBCoreService;
constructor(core: IGBCoreService) {
this.core = core;
}
importIfNotExistsBotPackage(
packageName: string,
localPath: string,
cb: GBServiceCallback<IGBInstance>
) {
let _this = this;
let packageJson = JSON.parse(
Fs.readFileSync(UrlJoin(localPath, "package.json"), "utf8")
);
let botId = packageJson.botId;
this.core.loadInstance(botId, (instance, err) => {
if (instance) {
cb(instance, null);
} else {
this.createInstanceInternal(packageName, localPath, packageJson, cb);
}
});
}
private createInstanceInternal(
packageName: string,
localPath: string,
packageJson: any,
cb: GBServiceCallback<IGBInstance>
) {
const settings = JSON.parse(
Fs.readFileSync(UrlJoin(localPath, "settings.json"), "utf8")
);
const servicesJson = JSON.parse(
Fs.readFileSync(UrlJoin(localPath, "services.json"), "utf8")
);
packageJson = Object.assign(packageJson, settings, servicesJson);
GuaribasInstance.create(packageJson).then((instance: IGBInstance) => {
// PACKAGE: security.json loading
let service = new SecService();
service.importSecurityFile(localPath, instance);
cb(instance, null);
});
}
}

View file

@ -1,400 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
const gBuilder = require("botbuilder");
const UrlJoin = require("url-join");
const Path = require("path");
const Fs = require("fs");
const Url = require("url");
const logger = require("../../../src/logger");
const WaitUntil = require("wait-until");
const Walk = require("fs-walk");
const express = require("express");
import { UniversalBot } from "botbuilder";
import { Session, MemoryBotStorage, Message } from "botbuilder";
import { GBCoreService } from "./GBCoreService";
import { GBConversationalService } from "./GBConversationalService";
import { GBConfigService } from "./GBConfigService";
import * as request from "request-promise-native";
import { GBMinInstance, IGBCoreService, IGBInstance, IGBPackage, GBError } from "botlib";
import { GBServiceCallback } from "botlib";
import { GBAnalyticsPackage } from "../../analytics.gblib";
import { GBCorePackage } from "../../core.gbapp";
import { GBKBPackage } from '../../kb.gbapp';
import { GBDeployer } from './GBDeployer';
import { GBSecurityPackage } from '../../security.gblib';
import { GBAdminPackage } from './../../admin.gbapp/index';
import { GBCustomerSatisfactionPackage } from "../../customer-satisfaction.gbapp";
/** Minimal service layer for a bot. */
export class GBMinService {
core: GBCoreService;
conversationalService: GBConversationalService;
deployer: GBDeployer;
deployFolder = "deploy";
corePackage = "core.gbai";
/**
* Static iniatialization of minimal instance.
*
* @param core Basic database services to identify instance, for example.
* @param cb Returns the loaded instance.
*/
constructor(
core: GBCoreService,
conversationalService: GBConversationalService,
deployer: GBDeployer
) {
this.core = core;
this.conversationalService = conversationalService;
this.deployer = deployer;
}
/** Constructs a new minimal instance for each bot. */
buildMin(cb: GBServiceCallback<GBMinInstance>, server: any, appPackages: Array<IGBPackage>) {
var _this = this;
// Serves default UI on root address '/'.
let uiPackage = "default.gbui";
server.use(
"/",
express.static(UrlJoin(this.deployFolder, uiPackage, "build"))
);
// Loads all bot instances from storage.
_this.core.loadInstances((instances: IGBInstance[], err) => {
// Gets the authorization key for each instance from Bot Service.
instances.forEach(instance => {
let options = {
url:
"https://directline.botframework.com/v3/directline/tokens/generate",
method: "POST",
headers: {
Authorization: `Bearer ${instance.webchatKey}`
}
};
request(options).then((response: string) => {
// Serves the bot information object via http so clients can get
// instance information stored on server.
let responseObject = JSON.parse(response);
server.get("/instances/:botId", (req, res) => {
// Returns the instance object to clients requesting bot info.
let botId = req.params.botId;
_this.core.loadInstance(
botId,
(instance: IGBInstance, err) => {
if (instance) {
res.send(
JSON.stringify({
instanceId: instance.instanceId,
botId: botId,
theme: instance.theme,
secret: instance.webchatKey, // TODO: Use token.
conversationId: responseObject.conversationId
})
);
} else {
let error = `Instance not found: ${botId}.`;
res.send(error);
logger.error(error);
}
}
);
});
});
// The minimal bot is built here.
let min = new GBMinInstance();
min.botId = instance.botId;
min.core = _this.core;
min.conversationalService = _this.conversationalService;
let connector = new gBuilder.ChatConnector({
appId: instance.marketplaceId,
appPassword: instance.marketplacePassword
});
// Serves individual URL for each bot conversational interface...
let url = `/api/messages/${instance.botId}`;
logger.trace(
`GeneralBots(${instance.engineName}) listening on: ${url}.`
);
server.post(url, connector.listen());
// Serves individual URL for each bot user interface.
let uiUrl = `/${instance.botId}`;
server.use(
uiUrl,
express.static(UrlJoin(this.deployFolder, uiPackage, "build"))
);
logger.trace(`Bot UI ${uiPackage} acessible at: ${uiUrl}.`);
// Prepares bot service.
let inMemoryStorage = new MemoryBotStorage();
min.bot = new gBuilder.UniversalBot(connector, {
storage: inMemoryStorage
});
// Call the loadBot event.
appPackages.forEach(e => e.loadBot(min));
// Setups handlers.
min.bot.use({
botbuilder: (session, next) => {
if (!session.privateConversationData.loaded) {
setTimeout(
() =>
`Sending loading instance to client ${min.instance.ui}.`,
min.conversationalService.sendEvent(
session,
"loadInstance",
min.instance // TODO: Send a new thiner object.
),
500
);
session.privateConversationData.loaded = true;
appPackages.forEach(e => {
e.onNewSession(min, session)
});
// PACKAGE: min.subjects = [];
}
next();
},
receive: function (event: any, next) {
logger.trace(
`Event RCV: (Type: ${event.type}, Name: ${event.name}, Value: ${
event.value
}).`
);
// PACKAGE: Provide loop here.
if (
event.type === "conversationUpdate" &&
event.membersAdded.length > 0 &&
event.membersAdded[0].name != "You"
) {
min.bot.beginDialog(event.address, "/");
} else if (event.name === "whoAmI") {
min.bot.beginDialog(event.address, "/whoAmI");
} else if (event.name === "showSubjects") {
min.bot.beginDialog(event.address, "/menu");
} else if (event.name === "giveFeedback") {
min.bot.beginDialog(event.address, "/feedback", {
fromMenu: true
});
} else if (event.name === "showFAQ") {
min.bot.beginDialog(event.address, "/faq");
} else if (event.name === "ask") {
min.bot.beginDialog(event.address, "/answer", {
query: event.data,
fromFaq: true
});
} else if (event.name === "quality") {
min.bot.beginDialog(event.address, "/quality", {
score: event.data
});
} else {
next();
}
},
send: function (event, next) {
this.core.createMessage(
this.min.conversation,
this.min.conversation.startedBy,
event.source,
(data, err) => {
logger.trace(event.source);
}
);
next();
}
});
let generalPackages = [GBAdminPackage, GBAnalyticsPackage, GBCorePackage, GBSecurityPackage, GBKBPackage, GBCustomerSatisfactionPackage];
generalPackages.forEach(e => {
logger.trace(`Loading package: ${e.name}...`);
let p = Object.create(e.prototype) as IGBPackage;
p.loadBot(min)
});
// Specialized load for each min instance.
cb(min, null);
});
});
}
/** Performs package deployment in all .gbai or default. */
public deployPackages(core: IGBCoreService, server: any, appPackages: Array<IGBPackage>, sysPackages: Array<IGBPackage>) {
return new Promise((resolve, reject) => {
try {
var _this = this;
let botsToProcess = 0, botsProcessed = 0;
let additionalPath = GBConfigService.get("ADDITIONAL_DEPLOY_PATH");
let paths = [this.deployFolder];
if (additionalPath) {
paths = paths.concat(additionalPath.toLowerCase().split(";"));
}
let botPackages = new Array<string>();
let generalPackages = new Array<string>();
function doIt(path) {
const isDirectory = source => Fs.lstatSync(source).isDirectory()
const getDirectories = source =>
Fs.readdirSync(source).map(name => Path.join(source, name)).filter(isDirectory)
let dirs = getDirectories(path);
dirs.forEach(element => {
if (element.endsWith('.gbot')) {
botPackages.push(element);
}
else {
generalPackages.push(element);
}
});
}
logger.trace(`Starting looking for generalPackages...`);
paths.forEach(e => {
logger.trace(`Looking in: ${e}...`);
doIt(e)
});
/** Deploys all .gbot files first. */
botPackages.forEach(e => {
logger.trace(`Deploying bot: ${e}...`);
this.deployer.deployBot(e, (data, err) => {
botsProcessed++;
});
});
/** Then all remaining generalPackages are loaded. */
generalPackages.forEach(filename => {
let filenameOnly = Path.basename(filename);
logger.trace(`Deploying package: ${filename}...`);
/** Handles apps for general bots - .gbapp must stay out of deploy folder. */
if (Path.extname(filename) === ".gbapp" || Path.extname(filename) === ".gblib") {
// Skips .gbapp inside deploy folder.
if (!filename.startsWith('deploy')) {
import(filename).then(m => {
let p = new m.Package();
p.loadPackage(core);
appPackages.push(p);
logger.trace(`App (.gbapp) deployed: ${filenameOnly}.`);
});
}
/** Themes for bots. */
} else if (Path.extname(filename) === ".gbtheme") {
server.use("/themes/" + filenameOnly, express.static(filename));
logger.trace(`Theme (.gbtheme) assets acessible at: ${"/themes/" + filenameOnly}.`);
/** Knowledge base for bots. */
} else if (Path.extname(filename) === ".gbkb") {
server.use(
"/kb/" + filenameOnly + "/subjects",
express.static(UrlJoin(filename, "subjects"))
);
logger.trace(`KB (.gbkb) assets acessible at: ${"/kb/" + filenameOnly}.`);
}
else if (Path.extname(filename) === ".gbui" || filename.endsWith(".git")) {
// Already Handled
}
/** Unknown package format. */
else {
let err = new Error(`Package type not handled: ${filename}.`);
reject(err);
}
botsProcessed++;
});
WaitUntil()
.interval(100)
.times(50)
.condition(function (cb) {
logger.trace(`Waiting for package deployment...`);
cb(botsProcessed == (generalPackages.length + botPackages.length));
})
.done(function (result) {
logger.trace(`Package deployment done.`);
resolve();
});
} catch (err) {
reject(err)
}
});
}
}

View file

@ -1,104 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
import { UniversalBot, Session, Prompts, ListStyle } from "botbuilder";
import UrlJoin from "url-join";
import { CSService } from '../services/CSService';
import { AzureText } from "pragmatismo-io-framework1";
import { GBMinInstance } from "botlib";
import { IGBDialog } from "botlib";
export class FeedbackDialog extends IGBDialog {
static setup(bot: UniversalBot, min: GBMinInstance) {
const service = new CSService();
bot.dialog("/feedbackNumber", [
function(session, args) {
session.sendTyping();
let msgs = [
"O que achou do meu atendimento, de 1 a 5?",
"Qual a nota do meu atendimento?",
"Como define meu atendimento numa escala de 1 a 5?"
];
Prompts.choice(session, msgs, "1|2|3|4|5", {
listStyle: ListStyle.button
});
},
function(session, results) {
let rate = results.response.entity;
service.updateConversationRate(session.userData.conversation, rate, item => {
let msgs = ["Obrigado!", "Obrigado por responder."];
session.send(msgs);
});
}
]);
bot.dialog("/feedback", [
function(session, args) {
if (args && args.fromMenu) {
let msgs = [
"Sugestões melhoram muito minha qualidade...",
"Obrigado pela sua iniciativa de sugestão."
];
session.send(msgs);
}
session.sendTyping();
let msgs = [
"O que achou do meu atendimento?",
"Como foi meu atendimento?",
"Gostaria de dizer algo sobre meu atendimento?"
];
Prompts.text(session, msgs);
},
function(session, results) {
AzureText.getSentiment(
min.instance.textAnalyticsKey,
results.response,
(err, rate) => {
if (!err && rate > 0) {
session.send("Bom saber que você gostou. Conte comigo.");
} else {
session.send(
"Vamos registrar sua questão, obrigado pela sinceridade."
);
}
session.replaceDialog('/ask', {isReturning: true});
}
);
}
]);
}
}

View file

@ -1,86 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
import { IGBDialog } from "botlib";
import { UniversalBot, Session, Prompts, ListStyle } from "botbuilder";
import UrlJoin from "url-join";
import { GBMinInstance } from "botlib";
import { CSService } from "../services/CSService";
const logger = require("../../../src/logger");
export class QualityDialog extends IGBDialog {
static setup(bot: UniversalBot, min: GBMinInstance) {
const service = new CSService();
bot.dialog("/quality", [
(session, args) => {
var score = args.score;
setTimeout(
() => min.conversationalService.sendEvent(session, "stop", null),
400
);
if (score == 0) {
let msg = [
"Desculpe-me, vamos tentar novamente.",
"Lamento... Vamos tentar novamente!",
"Desculpe-me. Por favor, tente escrever de outra forma?"
];
session.send(msg);
} else {
let msg = [
"Ótimo, obrigado por contribuir com sua resposta.",
"Certo, obrigado pela informação.",
"Obrigado pela contribuição."
];
session.send(msg);
service.insertQuestionAlternate(
min.instance.instanceId,
session.userData.lastQuestion,
session.userData.lastQuestionId,
(data, err) => {
logger.trace("QuestionAlternate inserted.");
}
);
session.replaceDialog('/ask', {isReturning: true});
}
}
]);
}
}

View file

@ -1,63 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
const UrlJoin = require("url-join");
import { GuaribasQuestionAlternate } from './models/index';
import { QualityDialog } from './dialogs/QualityDialog';
import { FeedbackDialog } from './dialogs/FeedbackDialog';
import { GBMinInstance, IGBPackage, IGBCoreService } from "botlib";
import { Session } from 'botbuilder';
import { Sequelize } from 'sequelize-typescript';
export class GBCustomerSatisfactionPackage implements IGBPackage {
loadPackage(core: IGBCoreService, sequelize: Sequelize): void {
core.sequelize.addModels([
GuaribasQuestionAlternate
]);
}
unloadPackage(core: IGBCoreService): void {
}
loadBot(min: GBMinInstance): void {
FeedbackDialog.setup(min.bot, min);
QualityDialog.setup(min.bot, min);
}
unloadBot(min: GBMinInstance): void {
}
onNewSession(min: GBMinInstance, session: Session): void {
}
}

View file

@ -1,94 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
const logger = require("../../../src/logger");
const Path = require("path");
const Fs = require("fs");
const FsExtra = require("fs-extra");
const _ = require("lodash");
const Parse = require("csv-parse");
const Async = require("async");
const UrlJoin = require("url-join");
const Walk = require("fs-walk");
const WaitUntil = require("wait-until");
import { GBServiceCallback } from "botlib";
import { UrlJoin } from 'url-join';
import { GBDeployer } from "../../core.gbapp/services/GBDeployer";
import { GuaribasQuestionAlternate } from '../models';
import { GuaribasConversation } from '../../analytics.gblib/models';
export class CSService {
resolveQuestionAlternate(
instanceId: number,
questionTyped: string,
cb: GBServiceCallback<GuaribasQuestionAlternate>
) {
GuaribasQuestionAlternate.findOne({
where: {
instanceId: instanceId,
questionTyped: questionTyped
}
}).then((value: GuaribasQuestionAlternate) => {
cb(value, null);
});
}
insertQuestionAlternate(
instanceId: number,
questionTyped: string,
questionText: string,
cb: GBServiceCallback<GuaribasQuestionAlternate>
) {
GuaribasQuestionAlternate.create({
questionTyped: questionTyped,
questionText: questionText
}).then(item => {
if (cb) {
cb(item, null);
}
});
}
updateConversationRate(
conversation: GuaribasConversation,
rate: number,
cb: GBServiceCallback<GuaribasConversation>
) {
conversation.rate = rate;
conversation.save().then((value: GuaribasConversation) => {
cb(conversation, null);
});
}
}

View file

@ -1 +0,0 @@
package-lock=false

View file

@ -1,28 +0,0 @@
{
"name": "default.gbui",
"version": "0.0.9",
"private": true,
"homepage": ".",
"dependencies": {
"@fortawesome/fontawesome": "^1.1.3",
"@fortawesome/fontawesome-free-solid": "^5.0.6",
"@fortawesome/react-fontawesome": "0.1.0-3",
"botframework-webchat": "^0.11.4",
"deep-extend": "0.5.0",
"fetch": "1.1.0",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-helmet": "^5.2.0",
"react-player": "1.2.1",
"react-powerbi": "^0.1.7",
"react-scripts": "^1.1.1",
"react-transition-group": "^2.3.0-beta.0",
"url-join": "^4.0.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}

File diff suppressed because one or more lines are too long

View file

@ -1,263 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
import React from "react";
import GBMarkdownPlayer from "./players/GBMarkdownPlayer.js";
import GBImagePlayer from "./players/GBImagePlayer.js";
import GBVideoPlayer from "./players/GBVideoPlayer.js";
import GBBulletPlayer from "./players/GBBulletPlayer.js";
import SidebarMenu from "./components/SidebarMenu.js";
import GBCss from "./components/GBCss.js";
import { DirectLine } from "botframework-directlinejs";
import { ConnectionStatus } from "botframework-directlinejs";
import { Chat } from "botframework-webchat";
import GBPowerBIPlayer from "./players/GBPowerBIPlayer.js";
class GBUIApp extends React.Component {
constructor() {
super();
this.state = {
botConnection: null,
instance: null,
token: null
};
}
send(command) {
window.botConnection
.postActivity({
type: "event",
name: command,
locale: "en-us",
textFormat: "plain",
timestamp: new Date().toISOString(),
from: { id: "webUser", name: "You" }
})
.subscribe(console.log("EVENT SENT TO Guaribas."));
}
getUser() {
return { id: "webUser@gb", name: "You" };
}
postEvent(name, value) {
window.botConnection.postActivity({
type: "event",
value: value,
from: this.getUser(),
name: name
});
}
postMessage(value) {
window.botConnection.postActivity({
type: "message",
text: value,
from: this.getUser()
});
}
configureChat() {
var botId = window.location.href.split("/")[3];
if (!botId) {
botId = "[default]";
}
fetch("/instances/" + botId)
.then(res => res.json())
.then(
result => {
this.setupBotConnection(result.secret);
},
error => {
this.setState({
isLoaded: false,
err: error
});
}
);
}
setupBotConnection(secret) {
let _this = this;
window["botchatDebug"] = true;
const botConnection = new DirectLine({
secret: secret
});
botConnection.connectionStatus$.subscribe(connectionStatus => {
if (connectionStatus === ConnectionStatus.Online) {
botConnection.postActivity({
type: "event",
value: "startGB",
from: this.getUser(),
name: "startGB"
});
_this.setState({ botConnection: botConnection });
}
});
window.botConnection = botConnection;
this.postEvent("startGB", true);
botConnection.activity$
.filter(
activity =>
activity.type === "event" && activity.name === "loadInstance"
)
.subscribe(activity => {
_this.setState({ instance: activity.value });
});
botConnection.activity$
.filter(activity => activity.type === "event" && activity.name === "stop")
.subscribe(activity => {
if (_this.player) {
_this.player.stop();
}
});
botConnection.activity$
.filter(activity => activity.type === "event" && activity.name === "play")
.subscribe(activity => {
_this.setState({ playerType: activity.value.playerType });
_this.player.play(activity.value.data);
});
}
componentDidMount() {
this.configureChat();
}
render() {
let chat = <div />;
let playerComponent = "";
if (this.state.playerType) {
switch (this.state.playerType) {
case "markdown":
playerComponent = (
<GBMarkdownPlayer
app={this}
ref={player => {
this.player = player;
}}
/>
);
break;
case "bullet":
playerComponent = (
<GBBulletPlayer
app={this}
ref={player => {
this.player = player;
}}
/>
);
break;
case "video":
playerComponent = (
<GBVideoPlayer
app={this}
ref={player => {
this.player = player;
}}
/>
);
break;
case "image":
playerComponent = (
<GBImagePlayer
app={this}
ref={player => {
this.player = player;
}}
/>
);
break;
case "pbi":
playerComponent = (
<GBPowerBIPlayer
app={this}
ref={player => {
this.player = player;
}}
/>
);
break;
default:
console.log(
"GBERROR: Unknow player type specified on message from server."
);
break;
}
}
let sideBar = (
<div className="sidebar">
<SidebarMenu chat={this.chat} instance={this.state.instance} />
</div>
);
if (this.state.botConnection) {
chat = (
<Chat
ref={chat => {
this.chat = chat;
}}
botConnection={this.state.botConnection}
user={this.getUser()}
bot={{ id: "bot@gb", name: "Bot" }}
/>
);
}
if (!this.state.instance) {
sideBar = "";
}
return (
<div>
<GBCss instance={this.state.instance} />
{sideBar}
<div className="player">{playerComponent}</div>
{chat}
</div>
);
}
}
export default GBUIApp;

View file

@ -1,35 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
// TODO: runWithAdal(authContext, () => {
require('./indexApp');
// DISABLED: });

View file

@ -1,147 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
import React, { Component } from "react";
import { Report } from "react-powerbi";
import * as pbi from "powerbi-client";
class GBPowerBIPlayer extends Component {
send(value) {
setTimeout(() => {
window.botConnection
.postActivity({
type: "event",
name: "quality",
data: value,
locale: "en-us",
textFormat: "plain",
timestamp: new Date().toISOString(),
from: { id: "webUser", name: "You" }
})
.subscribe(console.log("success"));
}, 400);
}
constructor() {
super();
this.state = {
embedUrl: "",
accessToken: "",
filters: null
};
}
play(data) {
var jobId = 1;
const basicFilter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "PauiniJob",
column: "jobId"
},
operator: "Equals",
values: [jobId],
filterType: pbi.models.FilterType.BasicFilter
};
this.setState({
embedUrl: data.embedUrl,
accessToken: data.accessToken,
filters: [basicFilter]
});
}
stop() {
this.setState({
embedUrl: "",
accessToken: "",
filters: null
});
}
clickYes() {
this.send(1);
}
clickNo() {
this.send(0);
}
render() {
var quality = (
<div className="gb-markdown-player-quality">
<span ref={i => (this.quality = i)}>O relatório atende?</span>
&nbsp;&nbsp;
<button
className="gb-quality-button-yes"
onClick={() => this.clickYes()}
ref={i => (this.Yes = i)}
>
Sim
</button>
&nbsp;|&nbsp;
<button
className="gb-quality-button-no"
onClick={() => this.clickNo()}
ref={i => (this.No = i)}
>
Não
</button>
</div>
);
if (this.state.content === "") {
quality = "";
}
return (
<div ref={i => (this.playerText = i)} className="media-player">
<div className="media-player-container">
<div className="media-player-scroll">
<Report
embedUrl={this.state.embedUrl}
accessToken={this.state.accessToken}
filterPaneEnabled={true}
filters={this.state.filters}
navContentPaneEnabled={false}
/>
</div>
</div>
{quality}
</div>
);
}
}
export default GBPowerBIPlayer;

View file

@ -1,203 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
import { Prompts, UniversalBot, Session, ListStyle } from "botbuilder";
import { IGBDialog } from "botlib";
import { AzureText } from "pragmatismo-io-framework1";
import { GBMinInstance } from "botlib";
import { KBService } from './../services/KBService';
const logger = require("../../../src/logger");
export class AskDialog extends IGBDialog {
static setup(bot: UniversalBot, min: GBMinInstance) {
const service = new KBService();
bot.dialog("/answer", [
(session, args) => {
let text = "";
if (args && args.query) {
text = args.query;
} else if (args && args.fromFaq) {
let msgs = [
`Ótima escolha, procurando resposta para sua questão...`,
`Pesquisando sobre o termo...`,
`Aguarde, por favor, enquanto acho sua resposta...`
];
session.sendTyping();
session.send(msgs);
}
if (text === "") {
session.replaceDialog("/ask");
} else if (AzureText.isIntentNo(text)) {
session.replaceDialog("/feedback");
} else if (AzureText.isIntentYes(text)) {
session.replaceDialog("/menu");
} else {
AzureText.getSpelledText(
"1f1653cd23e941ce869af73bdf9ef272",
text,
(data, err) => {
if (data != text) {
logger.trace("Spelled Text: " + data);
text = data;
}
session.userData.lastQuestion = data;
service.ask(
min.instance,
text,
min.instance.searchScore,
session.userData.subjects,
resultsA => {
min.conversationalService.sendEvent(session, "stop", null);
if (resultsA && resultsA.answer) {
session.userData.isAsking = false;
service.sendAnswer(min.conversationalService,
session,
resultsA.answer
);
session.userData.lastQuestionId = resultsA.questionId;
session.replaceDialog("/ask", { isReturning: true });
} else {
//if (min.isAsking) {
// Second time with no filter.
service.ask(
min.instance,
text,
min.instance.searchScore,
null,
resultsB => {
if (resultsB && resultsB.answer) {
session.userData.isAsking = false;
if (session.userData.subjects.length > 0) {
let subjectText = `${KBService.getSubjectItemsSeparatedBySpaces(
session.userData.subjects
)}`;
let msgs = [
`Respondendo nao apenas sobre ${subjectText}... `,
`Respondendo de modo mais abrangente...`,
`Vou te responder de modo mais abrangente... Não apenas sobre ${subjectText}`
];
session.send(msgs);
}
session.userData.isAsking = false;
service.sendAnswer(min.conversationalService,
session,
resultsB.answer
);
session.replaceDialog("/ask", { isReturning: true });
session.userData.lastQuestionId = resultsB.questionId;
} else {
min.conversationalService.runNLP(
session,
min,
text,
(data, error) => {
if (!data)
{
let msgs = [
"Desculpe-me, não encontrei nada a respeito.",
"Lamento... Não encontrei nada sobre isso. Vamos tentar novamente?",
"Desculpe-me, não achei nada parecido. Poderia tentar escrever de outra forma?"
];
session.send(msgs);
session.replaceDialog("/ask", { isReturning: true });
}
}
);
}
}
);
}
}
);
}
);
}
}
]);
bot
.dialog("/ask", [
(session, args) => {
session.userData.isAsking = true;
let text = [
`Pergunte-me sobre qualquer assunto ou digite **menu** para conhecer uma lista de opções.`,
`Pode perguntar sobre qualquer assunto... Ou digita **menu** para conhecer uma lista de opções.`,
`Faça qualquer pergunta ou também posso te mostrar o **menu** de assuntos sempre que precisar...`
];
if (session.userData.subjects.length > 0) {
text = [
`Faça sua pergunta...`,
`Pode perguntar sobre o assunto em questão... `,
`Qual a pergunta?`
];
}
if (args && args.isReturning) {
text = [
"Sobre o que mais posso ajudar?",
"Então, posso ajudar em algo a mais?",
"Deseja fazer outra pergunta?"
];
}
Prompts.text(session, text);
},
(session, results) => {
session.replaceDialog("/answer", { query: results.response });
}
])
.triggerAction({
matches: /^(procurar|bing|google|perguntar)/i
});
bot.beginDialogAction("ask", "/ask");
}
}

View file

@ -1,72 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
import { KBService } from './../services/KBService';
import { IGBDialog } from "botlib";
import { Prompts, UniversalBot, Session, ListStyle } from "botbuilder";
import UrlJoin from "url-join";
import { GBMinInstance } from "botlib";
export class FaqDialog extends IGBDialog {
static setup(bot: UniversalBot, min: GBMinInstance) {
const service = new KBService();
bot
.dialog("/faq", [
(session, args) => {
service.getFaqBySubjectArray("faq", null, (data, err) => {
if (data) {
min.conversationalService.sendEvent(session, "play", {
playerType: "bullet",
data: data.slice(0, 10)
});
let msgs = [
"Veja algumas perguntas mais frequentes logo na tela. Clique numa delas para eu responder.",
"Você pode clicar em alguma destas perguntas da tela que eu te respondo de imediato.",
"Veja a lista que eu preparei logo aí na tela..."
];
session.endDialog(msgs);
}
});
}
])
.triggerAction({
matches: /^(faq|perguntas frequentes)/i
});
bot.beginDialogAction("faq", "/faq");
}
}

View file

@ -1,191 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
import { Length } from "sequelize-typescript";
import {
UniversalBot,
Session,
Message,
AttachmentLayout,
CardAction,
HeroCard,
CardImage
} from "botbuilder";
import UrlJoin from "url-join";
import { IGBDialog } from "botlib";
import { GBMinInstance } from "botlib";
import { AzureText } from "pragmatismo-io-framework1";
import { GuaribasSubject } from '../models';
import { KBService } from "../services/KBService";
const UrlJoin = require("url-join");
const WaitUntil = require("wait-until");
export class MenuDialog extends IGBDialog {
static setup(bot: UniversalBot, min: GBMinInstance) {
var service = new KBService();
bot
.dialog("/menu", [
(session, args) => {
var rootSubjectId = null;
var botId = min.instance.botId;
var msg = session.message;
if (msg.attachments && msg.attachments.length > 0) {
var attachment = msg.attachments[0];
}
if (args && args.data) {
var subject = JSON.parse(args.data); // ?
if (subject.to) {
let dialog = subject.to.split(":")[1];
session.replaceDialog("/" + dialog);
session.endDialog();
return;
}
session.userData.subjects.push(subject);
rootSubjectId = subject.subjectId;
if (session.userData.subjects.length > 0) {
service.getFaqBySubjectArray(
"menu",
session.userData.subjects,
(data, err) => {
min.conversationalService.sendEvent(session, "play", {
playerType: "bullet",
data: data.slice(0, 6)
});
}
);
}
} else {
session.userData.subjects = [];
session.sendTyping();
WaitUntil()
.interval(2000)
.times(1)
.condition(function(cb) {
return false;
})
.done(function(result) {
let msgs = [
"Aqui estão algumas categorias de assuntos...",
"Selecionando o assunto você pode me ajudar a encontrar a resposta certa...",
"Você pode selecionar algum dos assuntos abaixo e perguntar algo..."
];
session.send(msgs);
});
session.userData.isAsking = false;
}
service.getSubjectItems(
min.instance.instanceId,
rootSubjectId,
data => {
var msg = new Message(session);
msg.attachmentLayout(AttachmentLayout.carousel);
var attachments = [];
data.forEach(function(item: GuaribasSubject) {
var subject = item;
var button = CardAction.dialogAction(
session,
"menuAction",
JSON.stringify({
title: subject.title,
subjectId: subject.subjectId,
to: subject.to
}),
"Selecionar"
);
var card = new HeroCard(session)
.title(subject.title)
.text(subject.description)
.images([
CardImage.create(
session,
UrlJoin(
"/kb",
min.instance.kb,
"subjects",
"subject.png" // TODO: subject.internalId + ".png" or fallback to subject.png
)
)
]) // Using public dir of ui.
.buttons([button]);
attachments.push(card);
});
if (attachments.length == 0) {
if (session.userData.subjects && session.userData.subjects.length > 0) {
session.send(
`Vamos pesquisar sobre ${KBService.getFormattedSubjectItems(
session.userData.subjects
)}?`
);
}
session.replaceDialog("/ask", {});
} else {
msg.attachments(attachments);
session.send(msg);
}
}
);
session.userData.isAsking = true;
},
function(session, results) {
var text = results.response;
if (AzureText.isIntentNo(text)) {
session.replaceDialog("/feedback");
} else {
session.replaceDialog("/ask");
}
}
])
.triggerAction({
matches: /^(menu)/i
});
bot.beginDialogAction("menuAction", "/menu");
}
}

View file

@ -1,71 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
const UrlJoin = require("url-join");
import { GuaribasAnswer, GuaribasQuestion, GuaribasSubject } from './models/index';
import { GBMinInstance, IGBPackage } from "botlib";
import { Session } from 'botbuilder';
import { AskDialog } from "./dialogs/AskDialog";
import { FaqDialog } from "./dialogs/FaqDialog";
import { MenuDialog } from "./dialogs/MenuDialog";
import { Sequelize } from 'sequelize-typescript';
import { IGBCoreService } from 'botlib';
export class GBKBPackage implements IGBPackage {
loadPackage(core: IGBCoreService, sequelize: Sequelize): void {
core.sequelize.addModels([
GuaribasAnswer,
GuaribasQuestion,
GuaribasSubject
]);
}
unloadPackage(core: IGBCoreService): void {
}
loadBot(min: GBMinInstance): void {
AskDialog.setup(min.bot, min);
FaqDialog.setup(min.bot, min);
MenuDialog.setup(min.bot, min);
}
unloadBot(min: GBMinInstance): void {
}
onNewSession(min: GBMinInstance, session: Session): void {
}
}

View file

@ -1,217 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
import {
Sequelize,
DataTypes,
DataTypeUUIDv4,
DataTypeDate,
DataTypeDecimal
} from "sequelize";
import {
Table,
Column,
Model,
HasMany,
BelongsTo,
BelongsToMany,
Length,
ForeignKey,
CreatedAt,
UpdatedAt,
DataType,
IsUUID,
PrimaryKey,
AutoIncrement
} from "sequelize-typescript";
import { GuaribasUser } from "../../security.gblib/models";
import { GuaribasInstance, GuaribasPackage } from "../../core.gbapp/models/GBModel";
@Table
export class GuaribasSubject extends Model<GuaribasSubject> {
@PrimaryKey
@AutoIncrement
@Column
subjectId: number;
@Column internalId: string;
@Column title: string;
@Column description: string;
@Column from: string;
@Column to: string;
@ForeignKey(() => GuaribasSubject)
@Column
parentSubjectId: number;
@BelongsTo(() => GuaribasSubject, "parentSubjectId")
parentSubject: GuaribasSubject;
@HasMany(() => GuaribasSubject, {foreignKey: "parentSubjectId"})
childrenSubjects: GuaribasSubject[];
@ForeignKey(() => GuaribasInstance)
@Column
instanceId: number;
@BelongsTo(() => GuaribasInstance)
instance: GuaribasInstance;
@ForeignKey(() => GuaribasUser)
@Column
responsibleUserId: number;
@BelongsTo(() => GuaribasUser)
responsibleUser: GuaribasUser;
@ForeignKey(() => GuaribasPackage)
@Column
packageId: number;
@BelongsTo(() => GuaribasPackage)
package: GuaribasPackage;
}
@Table
export class GuaribasQuestion extends Model<GuaribasQuestion> {
@PrimaryKey
@AutoIncrement
@Column
questionId: number;
@Column({ type: DataType.STRING(64) })
@Column
subject1: string;
@Column({ type: DataType.STRING(64) })
@Column
subject2: string;
@Column({ type: DataType.STRING(64) })
@Column
subject3: string;
@Column({ type: DataType.STRING(64) })
@Column
subject4: string;
@Column({ type: DataType.STRING(1024) })
@Column
keywords: string;
@Column({ type: DataType.STRING(512) })
from: string;
@Column({ type: DataType.STRING(512) })
to: string;
@Column({ type: DataType.TEXT })
content: string;
@Column
@CreatedAt
creationDate: Date;
@Column
@UpdatedAt
updatedOn: Date;
@ForeignKey(() => GuaribasAnswer)
@Column
answerId: number;
@BelongsTo(() => GuaribasInstance)
instance: GuaribasInstance;
@ForeignKey(() => GuaribasInstance)
@Column
instanceId: number;
@ForeignKey(() => GuaribasPackage)
@Column
packageId: number;
@BelongsTo(() => GuaribasPackage)
package: GuaribasPackage;
}
@Table
export class GuaribasAnswer extends Model<GuaribasAnswer> {
@PrimaryKey
@AutoIncrement
@Column
answerId: number;
@Length({ min: 0, max: 512 })
@Column
media: string;
@Length({ min: 0, max: 12 })
@Column
format: string;
@Column({ type: DataType.TEXT })
content: string;
@Column
@CreatedAt
creationDate: Date;
@Column
@UpdatedAt
updatedOn: Date;
@HasMany(() => GuaribasQuestion)
questions: GuaribasQuestion[];
@ForeignKey(() => GuaribasInstance)
@Column
instanceId: number;
@ForeignKey(() => GuaribasPackage)
@Column
packageId: number;
@BelongsTo(() => GuaribasPackage)
package: GuaribasPackage;
}

View file

@ -1,640 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
const logger = require("../../../src/logger");
const Path = require("path");
const Fs = require("fs");
const Parse = require("csv-parse");
const Async = require("async");
const UrlJoin = require("url-join");
const Walk = require("fs-walk");
const WaitUntil = require("wait-until");
const marked = require("marked");
import { GuaribasQuestion, GuaribasAnswer, GuaribasSubject }from "../models";
import { GBServiceCallback, IGBCoreService, IGBConversationalService, IGBInstance } from "botlib";
import { AzureSearch } from "pragmatismo-io-framework1";
import { GBCoreService } from 'deploy/core.gbapp/services/GBCoreService';
import { GBDeployer } from "../../core.gbapp/services/GBDeployer";
import { GBConversationalService } from "../../core.gbapp/services/GBConversationalService";
import { Session } from "botbuilder";
import { GuaribasPackage } from "../../core.gbapp/models/GBModel";
export class KBService {
getAnswerById(
instanceId: number,
answerId: number,
cb: GBServiceCallback<GuaribasAnswer>
) {
GuaribasAnswer.findAll({
where: {
instanceId: instanceId,
answerId: answerId
}
}).then((item: GuaribasAnswer[]) => {
cb(item[0], null);
});
}
getAnswerByText(
instanceId: number,
text: string,
cb: GBServiceCallback<any>
) {
GuaribasQuestion.findOne({
where: {
instanceId: instanceId,
content: text
}
}).then((question: GuaribasQuestion) => {
GuaribasAnswer.findOne({
where: {
instanceId: instanceId,
answerId: question.answerId
}
}).then((answer: GuaribasAnswer) => {
cb({ question: question, answer: answer }, null);
});
});
}
addAnswer(obj: GuaribasAnswer, cb: GBServiceCallback<GuaribasAnswer>) {
GuaribasAnswer.create(obj).then(item => {
if (cb) {
cb(item, null);
}
});
}
ask(
instance: IGBInstance,
what: string,
searchScore: number,
subjects: GuaribasSubject[],
cb: GBServiceCallback<any>
) {
if (instance.searchKey === "") {
cb(null, null);
return;
}
// Builds search query.
what = what.replace("?", " ");
what = what.replace("!", " ");
what = what.replace(".", " ");
what = what.replace("/", " ");
what = what.replace("\\", " ");
if (subjects) {
what = `${what} ${KBService.getSubjectItemsSeparatedBySpaces(
subjects
)}`;
}
// TODO: Filter by instance. what = `${what}&$filter=instanceId eq ${instanceId}`;
// Performs search.
var _this = this;
if (instance.searchKey) {
let service = new AzureSearch(
instance.searchKey,
instance.searchHost,
instance.searchIndex,
instance.searchIndexer
);
service.search(what, (err: any, results: any) => {
if (results && results.length > 0) {
// Ponders over configuration.
if (results[0]["@search.score"] >= searchScore) {
_this.getAnswerById(
instance.instanceId,
results[0].answerId,
(answer, err) => {
cb({ answer: answer, questionId: results[0].questionId }, null);
}
);
} else {
cb(null, null);
}
} else {
cb(null, null);
}
});
} else {
this.getAnswerByText(instance.instanceId, what, (data, err) => {
cb({ answer: data.answer, questionId: data.question.questionId }, null);
});
}
}
createGuaribasKbIndex(cb, name) {
let _this = this;
let schema = {
name: name,
fields: [
{
name: "questionId",
type: "Edm.String",
searchable: false,
filterable: false,
retrievable: true,
sortable: false,
facetable: false,
key: true
},
{
name: "subject1",
type: "Edm.String",
searchable: true,
filterable: false,
retrievable: false,
sortable: false,
facetable: false,
key: false
},
{
name: "subject2",
type: "Edm.String",
searchable: true,
filterable: false,
retrievable: false,
sortable: false,
facetable: false,
key: false
},
{
name: "subject3",
type: "Edm.String",
searchable: true,
filterable: false,
retrievable: false,
sortable: false,
facetable: false,
key: false
},
{
name: "subject4",
type: "Edm.String",
searchable: true,
filterable: false,
retrievable: false,
sortable: false,
facetable: false,
key: false
},
{
name: "content",
type: "Edm.String",
searchable: true,
filterable: false,
retrievable: false,
sortable: false,
facetable: false,
key: false
},
{
name: "answerId",
type: "Edm.Int32",
searchable: false,
filterable: false,
retrievable: true,
sortable: false,
facetable: false,
key: false
},
{
name: "instanceId",
type: "Edm.Int32",
searchable: false,
filterable: true,
retrievable: true,
sortable: false,
facetable: false,
key: false
},
{
name: "packageId",
type: "Edm.Int32",
searchable: false,
filterable: true,
retrievable: true,
sortable: false,
facetable: false,
key: false
}
],
scoringProfiles: [],
defaultScoringProfile: null,
corsOptions: null
};
// TODO: Migrate to Azure Search.
// this.client.createIndex(schema, function(err, schemaReturned) {
// let schemaIndexer = {
// name: _this.searchIndexer,
// description: 'gb',
// dataSourceName: 'gb', // TODO: Create it too dynamically from .env.
// targetIndexName: _this.searchIndex,
// parameters: {
// 'maxFailedItems' : 10,
// 'maxFailedItemsPerBatch' : 5,
// 'base64EncodeKeys': false,
// 'batchSize': 500
// }};
// // create/update an indexer
// _this.client.createIndexer(schemaIndexer, function(err, schemaIndexerReturned){
// cb(schemaIndexerReturned, err);
// });
// });
}
static getFormattedSubjectItems(subjects: GuaribasSubject[]) {
if (!subjects) return "";
let out = [];
subjects.forEach(subject => {
out.push(subject.title);
});
return out.join(", ");
}
static getSubjectItemsSeparatedBySpaces(subjects: GuaribasSubject[]) {
let out = [];
subjects.forEach(subject => {
out.push(subject.title);
});
return out.join(" ");
}
getSubjectItems(
instanceId: number,
parentId: number,
cb: GBServiceCallback<GuaribasSubject[]>
) {
var where = { parentSubjectId: parentId, instanceId: instanceId };
GuaribasSubject.findAll({
where: where
})
.then((values: GuaribasSubject[]) => {
cb(values, null);
})
.error(reason => {
cb(null, reason);
});
}
getFaqBySubjectArray(from: string, subjects: any, cb) {
let where = {
from: from
};
if (subjects) {
if (subjects[0]) {
where["subject1"] = subjects[0].title;
}
if (subjects[1]) {
where["subject2"] = subjects[1].title;
}
if (subjects[2]) {
where["subject3"] = subjects[2].title;
}
if (subjects[3]) {
where["subject4"] = subjects[3].title;
}
}
GuaribasQuestion.findAll({
where: where
})
.then((items: GuaribasQuestion[]) => {
if (!items) items = [];
if (items.length == 0) {
cb([], null);
} else {
cb(items, null);
}
})
.catch(reason => {
if (reason.message.indexOf("no such table: IGBInstance") != -1) {
cb([], null);
} else {
cb(null, reason);
logger.trace(`GuaribasServiceError: ${reason}`);
}
});
}
importKbTabularFile(
basedir: string,
filename: string,
instanceId: number,
packageId: number,
cb
) {
var filePath = UrlJoin(basedir, filename);
var parser = Parse(
{
delimiter: "\t"
},
function (err, data) {
Async.eachSeries(data, function (line, callback) {
callback();
let subjectsText = line[0];
var from = line[1];
var to = line[2];
var question = line[3];
var answer = line[4];
// Skip the first line.
if (!(subjectsText === "subjects" && from == "from")) {
let format = ".txt";
// Extract answer from external media if any.
if (answer.indexOf(".md") > -1) {
let mediaFilename = UrlJoin(basedir, "..", "articles", answer);
if (Fs.existsSync(mediaFilename)) {
answer = Fs.readFileSync(mediaFilename, "utf8");
format = ".md";
} else {
logger.trace("[GBImporter] File not found: ", mediaFilename);
answer =
"Por favor, contate a administração para rever esta pergunta.";
}
}
let subjectArray = subjectsText.split(".");
let subject1: string,
subject2: string,
subject3: string,
subject4: string;
var indexer = 0;
subjectArray.forEach(element => {
if (indexer == 0) {
subject1 = subjectArray[indexer].substring(0, 63);
} else if (indexer == 1) {
subject2 = subjectArray[indexer].substring(0, 63);
} else if (indexer == 2) {
subject3 = subjectArray[indexer].substring(0, 63);
} else if (indexer == 3) {
subject4 = subjectArray[indexer].substring(0, 63);
}
indexer++;
});
GuaribasAnswer.create({
instanceId: instanceId,
content: answer,
format: format,
packageId: packageId
}).then(function (answer: GuaribasAnswer) {
GuaribasQuestion.create({
from: from,
to: to,
subject1: subject1,
subject2: subject2,
subject3: subject3,
subject4: subject4,
content: question,
instanceId: instanceId,
answerId: answer.answerId,
packageId: packageId
});
});
} else {
logger.warn("[GBImporter] Missing header in file: ", filename);
}
});
}
);
Fs.createReadStream(filePath, {
encoding: "UCS-2"
}).pipe(parser);
}
sendAnswer(conversationalService: IGBConversationalService, session: Session, answer: GuaribasAnswer) {
if (answer.content.endsWith('.mp4')) {
conversationalService.sendEvent(session, "play", {
playerType: "video",
data: answer.content
});
}else if (answer.content.length > 140) {
let msgs = [
"Vou te responder na tela para melhor visualização...",
"A resposta está na tela...",
"Veja a resposta na tela..."
];
session.send(msgs);
var html = answer.content;
if (answer.format === ".md") {
marked.setOptions({
renderer: new marked.Renderer(),
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false,
xhtml: false
});
html = marked(answer.content);
}
conversationalService.sendEvent(session, "play", { playerType: "markdown", data: html });
} else {
session.send(answer.content);
conversationalService.sendEvent(session, "stop", null);
}
}
importKbPackage(
localPath: string,
packageStorage: GuaribasPackage,
instance: IGBInstance
) {
this.importSubjectFile(
packageStorage.packageId,
UrlJoin(localPath, "subjects.json"),
instance
);
let _this = this;
setTimeout(() => {
_this.importKbTabularDirectory(
localPath,
instance,
packageStorage.packageId
);
}, 3000);
}
importKbTabularDirectory(
localPath: string,
instance: IGBInstance,
packageId: number
) {
let _this = this;
Walk.files(
UrlJoin(localPath, "tabular"),
(basedir, filename, stat, next) => {
if (filename.endsWith(".tsv")) {
_this.importKbTabularFile(
basedir,
filename,
instance.instanceId,
packageId,
(data, err) => {
if (err) {
logger.trace(err);
} else {
logger.trace("Import KB done.");
}
}
);
}
},
function (err) {
if (err) logger.trace(err);
}
);
}
importSubjectFile(
packageId: number,
filename: string,
instance: IGBInstance
) {
var subjects = JSON.parse(Fs.readFileSync(filename, "utf8"));
function doIt(subjects: GuaribasSubject[], parentSubjectId: number) {
Async.eachSeries(subjects, (item, callback) => {
let mediaFilename = item.id + ".png";
GuaribasSubject.create({
internalId: item.id,
parentSubjectId: parentSubjectId,
instanceId: instance.instanceId,
from: item.from,
to: item.to,
title: item.title,
description: item.description,
packageId: packageId
}).then((value: any) => {
if (item.children) {
doIt(item.children, value.subjectId);
}
});
callback();
});
}
doIt(subjects.children, null);
}
undeployKbFromStorage(
instance: IGBInstance,
packageId: number,
cb: GBServiceCallback<any>
) {
GuaribasQuestion.destroy({
where: { instanceId: instance.instanceId, packageId: packageId }
}).then(value => {
GuaribasAnswer.destroy({
where: { instanceId: instance.instanceId, packageId: packageId }
}).then(value => {
GuaribasSubject.destroy({
where: { instanceId: instance.instanceId, packageId: packageId }
}).then(value => {
GuaribasPackage.destroy({
where: { instanceId: instance.instanceId, packageId: packageId }
}).then(value => {
var search = new AzureSearch(
instance.searchKey,
instance.searchHost,
instance.searchIndex,
instance.searchIndexer
);
logger.trace("rebuildIndex called.");
search.rebuildIndex(() => {
logger.trace("rebuildIndex done.");
cb(null, null);
});
});
});
});
});
}
/**
* Deploys a knowledge base to the storage using the .gbkb format.
*
* @param localPath Path to the .gbkb folder.
* @param cb Package instance or error info.
*/
deployKb(core: IGBCoreService, deployer: GBDeployer, localPath: string, cb: GBServiceCallback<any>) {
let packageType = Path.extname(localPath);
let packageName = Path.basename(localPath);
logger.trace("[GBDeployer] Opening package: ", packageName);
let packageObject = JSON.parse(
Fs.readFileSync(UrlJoin(localPath, "package.json"), "utf8")
);
core.loadInstance(packageObject.botId, (instance, err) => {
deployer.deployPackageToStorage(
instance.instanceId,
packageName,
(p, err) => {
this.importKbPackage(localPath, p, instance);
setTimeout(() => {
cb(null, null);
}, 8000);
}
);
});
}
}

View file

@ -1,134 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
"use strict";
import {
Sequelize,
DataTypes,
DataTypeUUIDv4,
DataTypeDate,
DataTypeDecimal
} from "sequelize";
import {
Table,
Column,
Model,
HasMany,
BelongsTo,
BelongsToMany,
Length,
ForeignKey,
CreatedAt,
UpdatedAt,
DataType,
IsUUID,
PrimaryKey,
AutoIncrement
} from "sequelize-typescript";
import { GuaribasInstance } from "../../core.gbapp/models/GBModel";
@Table
export class GuaribasUser extends Model<GuaribasUser> {
@PrimaryKey
@AutoIncrement
@Column
userId: number;
@Column displayName: string;
@Column userSystemId: string;
@Column userName: string;
@Column defaultChannel: string;
@Column email: string;
@Column({ type: DataType.STRING(512) })
@Column
internalAddress: string;
@ForeignKey(() =>
GuaribasInstance)
@Column
instanceId: number;
@BelongsTo(() => GuaribasInstance)
instance: GuaribasInstance;
}
@Table
export class GuaribasGroup extends Model<GuaribasGroup> {
@PrimaryKey
@AutoIncrement
@Column
groupId: number;
@Length({ min: 0, max: 512 })
@Column
displayName: string;
@ForeignKey(() => GuaribasInstance)
@Column
instanceId: number;
@BelongsTo(() => GuaribasInstance )
instance: GuaribasInstance;
}
@Table
export class GuaribasUserGroup extends Model<GuaribasUserGroup> {
@ForeignKey(() => GuaribasUser)
@Column
userId: number;
@ForeignKey(() => GuaribasGroup)
@Column
groupId: number;
@ForeignKey(() => GuaribasInstance)
@Column
instanceId: number;
@BelongsTo(() => GuaribasInstance)
instance: GuaribasInstance;
@BelongsTo(() => GuaribasGroup)
group: GuaribasGroup;
@BelongsTo(() => GuaribasUser)
user: GuaribasUser;
}

View file

@ -1,103 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
const Path = require("path");
const Fs = require("fs");
const _ = require("lodash");
const Parse = require("csv-parse");
const Async = require("async");
const UrlJoin = require("url-join");
const Walk = require("fs-walk");
const logger = require("../../../src/logger");
import { GBServiceCallback, GBService, IGBInstance } from "botlib";
import { GuaribasGroup, GuaribasUser, GuaribasUserGroup } from "../models";
export class SecService extends GBService {
importSecurityFile(localPath: string, instance: IGBInstance) {
var security = JSON.parse(
Fs.readFileSync(UrlJoin(localPath, "security.json"), "utf8")
);
security.groups.forEach(group => {
let groupDb = GuaribasGroup.build({
instanceId: instance.instanceId,
displayName: group.displayName
});
groupDb.save().then(groupDb => {
group.users.forEach(user => {
let userDb = GuaribasUser.build({
instanceId: instance.instanceId,
groupId: groupDb.groupId,
userName: user.userName
});
userDb.save().then(userDb => {
let userGroup = GuaribasUserGroup.build();
userGroup.groupId = groupDb.groupId;
userGroup.userId = userDb.userId;
userGroup.save();
});
});
});
});
}
ensureUser(
instanceId: number,
userSystemId: string,
userName: string,
address: string,
channelName: string,
displayName: string,
cb: GBServiceCallback<GuaribasUser>
) {
GuaribasUser.findOne({
attributes: ["instanceId", "internalAddress"],
where: {
instanceId: instanceId,
userSystemId: userSystemId
}
}).then(user => {
if (!user) {
user = GuaribasUser.build();
}
user.userSystemId = userSystemId;
user.userName = userName;
user.displayName = displayName;
user.internalAddress = address;
user.email = userName;
user.defaultChannel = channelName;
user.save();
cb(user, null);
});
}
}

1248
directline-3.0.json Normal file

File diff suppressed because one or more lines are too long

1
docs/_config.yml Normal file
View file

@ -0,0 +1 @@
theme: jekyll-theme-minimal

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 261 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 KiB

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 855 B

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1 @@
window.searchData = {"kinds":{"128":"Class","512":"Constructor","1024":"Property","2048":"Method"},"rows":[{"id":0,"kind":128,"name":"RootData","url":"classes/rootdata.html","classes":"tsd-kind-class"},{"id":1,"kind":512,"name":"constructor","url":"classes/rootdata.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"RootData"},{"id":2,"kind":1024,"name":"publicAddress","url":"classes/rootdata.html#publicaddress","classes":"tsd-kind-property tsd-parent-kind-class","parent":"RootData"},{"id":3,"kind":1024,"name":"server","url":"classes/rootdata.html#server","classes":"tsd-kind-property tsd-parent-kind-class","parent":"RootData"},{"id":4,"kind":1024,"name":"sysPackages","url":"classes/rootdata.html#syspackages","classes":"tsd-kind-property tsd-parent-kind-class","parent":"RootData"},{"id":5,"kind":1024,"name":"appPackages","url":"classes/rootdata.html#apppackages","classes":"tsd-kind-property tsd-parent-kind-class","parent":"RootData"},{"id":6,"kind":1024,"name":"minService","url":"classes/rootdata.html#minservice","classes":"tsd-kind-property tsd-parent-kind-class","parent":"RootData"},{"id":7,"kind":1024,"name":"bootInstance","url":"classes/rootdata.html#bootinstance","classes":"tsd-kind-property tsd-parent-kind-class","parent":"RootData"},{"id":8,"kind":1024,"name":"minInstances","url":"classes/rootdata.html#mininstances","classes":"tsd-kind-property tsd-parent-kind-class","parent":"RootData"},{"id":9,"kind":1024,"name":"minBoot","url":"classes/rootdata.html#minboot","classes":"tsd-kind-property tsd-parent-kind-class","parent":"RootData"},{"id":10,"kind":1024,"name":"wwwroot","url":"classes/rootdata.html#wwwroot","classes":"tsd-kind-property tsd-parent-kind-class","parent":"RootData"},{"id":11,"kind":1024,"name":"entryPointDialog","url":"classes/rootdata.html#entrypointdialog","classes":"tsd-kind-property tsd-parent-kind-class","parent":"RootData"},{"id":12,"kind":128,"name":"GBServer","url":"classes/gbserver.html","classes":"tsd-kind-class"},{"id":13,"kind":1024,"name":"globals","url":"classes/gbserver.html#globals","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-static","parent":"GBServer"},{"id":14,"kind":2048,"name":"run","url":"classes/gbserver.html#run","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-static","parent":"GBServer"},{"id":15,"kind":512,"name":"constructor","url":"classes/gbserver.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"GBServer"}],"index":{"version":"2.3.9","fields":["name","parent"],"fieldVectors":[["name/0",[0,3.075]],["parent/0",[]],["name/1",[1,19.169]],["parent/1",[0,0.291]],["name/2",[2,24.277]],["parent/2",[0,0.291]],["name/3",[3,24.277]],["parent/3",[0,0.291]],["name/4",[4,24.277]],["parent/4",[0,0.291]],["name/5",[5,24.277]],["parent/5",[0,0.291]],["name/6",[6,24.277]],["parent/6",[0,0.291]],["name/7",[7,24.277]],["parent/7",[0,0.291]],["name/8",[8,24.277]],["parent/8",[0,0.291]],["name/9",[9,24.277]],["parent/9",[0,0.291]],["name/10",[10,24.277]],["parent/10",[0,0.291]],["name/11",[11,24.277]],["parent/11",[0,0.291]],["name/12",[12,13.291]],["parent/12",[]],["name/13",[13,24.277]],["parent/13",[12,1.256]],["name/14",[14,24.277]],["parent/14",[12,1.256]],["name/15",[1,19.169]],["parent/15",[12,1.256]]],"invertedIndex":[["apppackages",{"_index":5,"name":{"5":{}},"parent":{}}],["bootinstance",{"_index":7,"name":{"7":{}},"parent":{}}],["constructor",{"_index":1,"name":{"1":{},"15":{}},"parent":{}}],["entrypointdialog",{"_index":11,"name":{"11":{}},"parent":{}}],["gbserver",{"_index":12,"name":{"12":{}},"parent":{"13":{},"14":{},"15":{}}}],["globals",{"_index":13,"name":{"13":{}},"parent":{}}],["minboot",{"_index":9,"name":{"9":{}},"parent":{}}],["mininstances",{"_index":8,"name":{"8":{}},"parent":{}}],["minservice",{"_index":6,"name":{"6":{}},"parent":{}}],["publicaddress",{"_index":2,"name":{"2":{}},"parent":{}}],["rootdata",{"_index":0,"name":{"0":{}},"parent":{"1":{},"2":{},"3":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{},"10":{},"11":{}}}],["run",{"_index":14,"name":{"14":{}},"parent":{}}],["server",{"_index":3,"name":{"3":{}},"parent":{}}],["syspackages",{"_index":4,"name":{"4":{}},"parent":{}}],["wwwroot",{"_index":10,"name":{"10":{}},"parent":{}}]],"pipeline":[]}}

213
docs/reference/index.html Normal file
View file

@ -0,0 +1,213 @@
<!doctype html>
<html class="default no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>General Bots Open Core</title>
<meta name="description" content="Documentation for General Bots Open Core">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
<script async src="assets/js/search.js" id="search-script"></script>
</head>
<body>
<header>
<div class="tsd-page-toolbar">
<div class="container">
<div class="table-wrap">
<div class="table-cell" id="tsd-search" data-index="assets/js/search.json" data-base=".">
<div class="field">
<label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>
<input id="tsd-search-field" type="text" />
</div>
<ul class="results">
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="index.html" class="title">General Bots Open Core</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
<a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a>
<div class="tsd-filter-group">
<div class="tsd-select" id="tsd-filter-visibility">
<span class="tsd-select-label">All</span>
<ul class="tsd-select-list">
<li data-value="public">Public</li>
<li data-value="protected">Public/Protected</li>
<li data-value="private" class="selected">All</li>
</ul>
</div>
<input type="checkbox" id="tsd-filter-inherited" checked />
<label class="tsd-widget" for="tsd-filter-inherited">Inherited</label>
<input type="checkbox" id="tsd-filter-externals" checked />
<label class="tsd-widget" for="tsd-filter-externals">Externals</label>
</div>
</div>
<a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a>
</div>
</div>
</div>
</div>
<div class="tsd-page-title">
<div class="container">
<h1>General Bots Open Core</h1>
</div>
</div>
</header>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<div class="tsd-panel tsd-typography">
<table>
<thead>
<tr>
<th>Area</th>
<th>Status</th>
</tr>
</thead>
<tbody><tr>
<td>Releases</td>
<td><a href="https://www.npmjs.com/package/botserver/"><img src="https://img.shields.io/npm/dt/botserver.svg?logo=npm&label=botserver" alt="General Bots"></a> <a href="https://www.npmjs.com/package/botlib/"><img src="https://img.shields.io/npm/dt/botlib.svg?logo=npm&label=botlib" alt=".gbapp lib"></a> <a href="https://github.com/semantic-release/semantic-release"><img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg" alt="semantic-release"></a></td>
</tr>
<tr>
<td>Community</td>
<td><a href="https://stackoverflow.com/questions/tagged/generalbots"><img src="https://img.shields.io/stackexchange/stackoverflow/t/generalbots.svg" alt="StackExchange"></a> <a href="https://badges.frapsoft.com"><img src="https://badges.frapsoft.com/os/v2/open-source.svg" alt="Open-source"></a> <a href="http://makeapullrequest.com"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square" alt="PRs Welcome"></a> <a href="https://github.com/GeneralBots/BotServer/blob/master/LICENSE.txt"><img src="https://img.shields.io/badge/license-AGPL-blue.svg" alt="License"></a></td>
</tr>
<tr>
<td>Management</td>
<td><a href="https://gitHub.com/GeneralBots/BotServer/graphs/commit-activity"><img src="https://img.shields.io/badge/Maintained%3F-yes-green.svg" alt="Maintenance"></a></td>
</tr>
<tr>
<td>Security</td>
<td><a href="https://snyk.io/test/github/GeneralBots/BotServer"><img src="https://snyk.io/test/github/GeneralBots/BotServer/badge.svg" alt="Known Vulnerabilities"></a></td>
</tr>
<tr>
<td>Building &amp; Quality</td>
<td><a href="https://travis-ci.com/GeneralBots/BotServer"><img src="https://travis-ci.com/GeneralBots/BotServer.svg?branch=master" alt="Build Status"></a> <a href="https://coveralls.io/github/GeneralBots/BotServer"><img src="https://coveralls.io/repos/github/GeneralBots/BotServer/badge.svg" alt="Coverage Status"></a> <a href="https://github.com/prettier/prettier"><img src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square" alt="code style: prettier"></a></td>
</tr>
<tr>
<td>Packaging</td>
<td><a href="https://badge.fury.io"><img src="https://badge.fury.io/js/botserver.svg" alt="forthebadge"></a> <a href="https://github.com/GeneralBots/BotServer/releases/latest"><img src="https://camo.githubusercontent.com/0150c0f148d50fe9750ebc5d313581da699a8c50/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7a69702d646f776e6c6f61642d626c75652e737667" alt="ZipFile"></a> <a href="https://david-dm.org"><img src="https://david-dm.org/GeneralBots/botserver.svg" alt="Dependencies"></a> <a href="http://commitizen.github.io/cz-cli/"><img src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg" alt="Commitizen friendly"></a></td>
</tr>
<tr>
<td>Samples</td>
<td><a href="https://github.com/GeneralBots/BotServer/tree/master/packages/default.gbdialog">VBA</a> or <a href="https://github.com/GeneralBots/AzureADPasswordReset.gbapp"><img src="https://badges.frapsoft.com/typescript/code/typescript.svg?v=101" alt="TypeScript"></a></td>
</tr>
<tr>
<td><a href="https://github.com/lpicanco/docker-botserver">Docker Image</a></td>
<td><img src="https://img.shields.io/docker/automated/lpicanco/botserver.svg" alt="Docker Automated build"> <img src="https://img.shields.io/docker/build/lpicanco/botserver.svg" alt="Docker Build Status"> <img src="https://img.shields.io/microbadger/image-size/lpicanco/botserver.svg" alt="MicroBadger Size"> <img src="https://img.shields.io/microbadger/layers/lpicanco/botserver.svg" alt="MicroBadger Layers"> <img src="https://img.shields.io/docker/pulls/lpicanco/botserver.svg" alt="Docker Pulls"> <br/> <em>Provided by <a href="https://github.com/lpicanco/docker-botserver">@lpicanco</a></em></td>
</tr>
</tbody></table>
<a href="#general-bots" id="general-bots" style="color: inherit; text-decoration: none;">
<h2>General Bots</h2>
</a>
<p><img src="https://raw.githubusercontent.com/pragmatismo-io/BotServer/master/logo.png" alt="General Bot Logo"></p>
<p>General Bot is a strongly typed package based chat bot server focused in convention over configuration and code-less approaches, which brings software packages and application server concepts to help parallel bot development.</p>
<a href="#what-is-a-bot-server" id="what-is-a-bot-server" style="color: inherit; text-decoration: none;">
<h2>What is a Bot Server?</h2>
</a>
<p>Bot Server accelerates the process of developing a bot. It provisions all code
base, resources and deployment to the cloud, and gives you templates you can
choose from whenever you need a new bot. The server has a database and service
backend allowing you to further modify your bot package directly by downloading
a zip file, editing and uploading it back to the server (deploying process) with
no code. The Bot Server also provides a framework to develop bot packages in a more
advanced fashion writing custom code in editors like Visual Studio Code, Atom or Brackets.</p>
<p>Everyone can create bots by just copying and pasting some files and using their
favorite tools from Office (or any text editor) or Photoshop (or any image
editor). BASIC can be used to build custom dialogs so Bot can be extended just like VBA for Excel (currently in alpha).</p>
<p><img src="https://raw.githubusercontent.com/GeneralBots/BotBook/master/images/general-bots-reference-architecture.png" alt="General Bot Reference Architecture"></p>
<a href="#samples" id="samples" style="color: inherit; text-decoration: none;">
<h2>Samples</h2>
</a>
<p>Several samples, including a Bot for AD Password Reset, are avaiable on the <a href="https://github.com/GeneralBots">repository list</a>.</p>
<a href="#guide" id="guide" style="color: inherit; text-decoration: none;">
<h2>Guide</h2>
</a>
<p><a href="https://github.com/GeneralBots/BotBook/tree/master/book">Read the General Bots BotBook Guide</a>.</p>
<a href="#videos" id="videos" style="color: inherit; text-decoration: none;">
<h1>Videos</h1>
</a>
<p>Now with the General Bots server you can press F5 on Visual Studio to get a bot factory on your environment* published on November 10th, 2018.</p>
<p><a href="https://www.youtube.com/watch?v=AfKTwljoMOs"><img src="https://raw.githubusercontent.com/pragmatismo-io/BotServer/master/docs/images/video-01-thumb.jpg" alt="General Bot Video"></a></p>
<p>See how easy is to use &#39;hear&#39; and &#39;talk&#39; to build Microsoft BOT Framework v4 logic with plain BASIC * published on December 3rd, 2018.</p>
<p><a href="https://www.youtube.com/watch?v=yX1sF9n9628"><img src="https://raw.githubusercontent.com/pragmatismo-io/BotServer/master/docs/images/video-02-thumb.jpg" alt="See how easy is to use &#39;hear&#39; and &#39;talk&#39; to build Microsoft BOT Framework v4 logic with plain BASIC"></a></p>
<a href="#contributing" id="contributing" style="color: inherit; text-decoration: none;">
<h1>Contributing</h1>
</a>
<p>This project welcomes contributions and suggestions.
See our <a href="https://github.com/pragmatismo-io/BotServer/blob/master/CONTRIBUTING.md">Contribution Guidelines</a> for more details.</p>
<a href="#reporting-security-issues" id="reporting-security-issues" style="color: inherit; text-decoration: none;">
<h1>Reporting Security Issues</h1>
</a>
<p>Security issues and bugs should be reported privately, via email, to the Pragmatismo.io Security
team at <a href="mailto:security@pragmatismo.io">security@pragmatismo.io</a>. You should
receive a response within 24 hours. If for some reason you do not, please follow up via
email to ensure we received your original message. </p>
<a href="#license-amp-warranty" id="license-amp-warranty" style="color: inherit; text-decoration: none;">
<h1>License &amp; Warranty</h1>
</a>
<p>General Bot Copyright (c) Pragmatismo.io. All rights reserved.
Licensed under the AGPL-3.0. </p>
<p>According to our dual licensing model, this program can be used either
under the terms of the GNU Affero General Public License, version 3,
or under a proprietary license. </p>
<p>The texts of the GNU Affero General Public License with an additional
permission and of our proprietary license can be found at and
in the LICENSE file you have received along with this program.</p>
<p>This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.</p>
<p>&quot;General Bot&quot; is a registered trademark of Pragmatismo.io.
The licensing of the program under the AGPLv3 does not imply a
trademark license. Therefore any rights, title and interest in
our trademarks remain entirely with us.</p>
<p><a href="https://stackoverflow.com/questions/ask?tags=generalbots">:speech_balloon: Ask a question</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://github.com/GeneralBots/BotBook">:book: Read the Docs</a></p>
<p>General Bots Code Name is <a href="https://en.wikipedia.org/wiki/Guaribas">Guaribas</a>, the name of a city in Brazil, state of Piaui.
<a href="http://www.robertounger.com/en/">Roberto Mangabeira Unger</a>: &quot;No one should have to do work that can be done by a machine&quot;.</p>
</div>
</div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<nav class="tsd-navigation primary">
<ul>
<li class=" ">
<a href="modules.html">Exports</a>
</li>
</ul>
</nav>
<nav class="tsd-navigation secondary menu-sticky">
<ul class="before-current">
<li class=" tsd-kind-class">
<a href="classes/gbserver.html" class="tsd-kind-icon">GBServer</a>
</li>
<li class=" tsd-kind-class">
<a href="classes/rootdata.html" class="tsd-kind-icon">Root<wbr>Data</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<footer class="with-border-bottom">
<div class="container">
<h2>Legend</h2>
<div class="tsd-legend-group">
<ul class="tsd-legend">
<li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li>
<li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static method</span></li>
</ul>
</div>
</div>
</footer>
<div class="container tsd-generator">
<p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p>
</div>
<div class="overlay"></div>
<script src="assets/js/main.js"></script>
</body>
</html>

382
extensions.json Normal file
View file

@ -0,0 +1,382 @@
[
{
"extension": "aac",
"description": "AAC audio",
"category": "Music"
},
{
"extension": "abw",
"description": "AbiWord document",
"category": "Document"
},
{
"extension": "arc",
"description": "Archive document (multiple files embedded)",
"category": "Document"
},
{
"extension": "avif",
"description": "AVIF image",
"category": "Image"
},
{
"extension": "avi",
"description": "AVI: Audio Video Interleave",
"category": "Movie"
},
{
"extension": "azw",
"description": "Amazon Kindle eBook format",
"category": "Document"
},
{
"extension": "bin",
"description": "Any kind of binary data",
"category": "Other"
},
{
"extension": "bmp",
"description": "Windows OS/2 Bitmap Graphics",
"category": "Image"
},
{
"extension": "bz",
"description": "BZip archive",
"category": "Other"
},
{
"extension": "bz2",
"description": "BZip2 archive",
"category": "Other"
},
{
"extension": "cda",
"description": "CD audio",
"category": "Music"
},
{
"extension": "csh",
"description": "C-Shell script",
"category": "Executable"
},
{
"extension": "css",
"description": "Cascading Style Sheets (CSS)",
"category": "Other"
},
{
"extension": "csv",
"description": "Comma-separated values (CSV)",
"category": "Document"
},
{
"extension": "doc",
"description": "Microsoft Word",
"category": "Document"
},
{
"extension": "docx",
"description": "Microsoft Word (OpenXML)",
"category": "Document"
},
{
"extension": "eot",
"description": "MS Embedded OpenType fonts",
"category": "Other"
},
{
"extension": "epub",
"description": "Electronic publication (EPUB)",
"category": "Document"
},
{
"extension": "gz",
"description": "GZip Compressed Archive",
"category": "Other"
},
{
"extension": "gif",
"description": "Graphics Interchange Format (GIF)",
"category": "Image"
},
{
"extension": "htm",
"description": "HyperText Markup Language (HTML)",
"category": "Other"
},
{
"extension": "html",
"description": "HyperText Markup Language (HTML)",
"category": "Other"
},
{
"extension": "ico",
"description": "Icon format",
"category": "Image"
},
{
"extension": "ics",
"description": "iCalendar format",
"category": "Document"
},
{
"extension": "jar",
"description": "Java Archive (JAR)",
"category": "Executable"
},
{
"extension": "jpeg",
"description": "JPEG images",
"category": "Image"
},
{
"extension": "jpg",
"description": "JPEG images",
"category": "Image"
},
{
"extension": "js",
"description": "JavaScript",
"category": "Other"
},
{
"extension": "json",
"description": "JSON format",
"category": "Other"
},
{
"extension": "jsonld",
"description": "JSON-LD format",
"category": "Other"
},
{
"extension": "mid",
"description": "Musical Instrument Digital Interface (MIDI)",
"category": "Music"
},
{
"extension": "midi",
"description": "Musical Instrument Digital Interface (MIDI)",
"category": "Music"
},
{
"extension": "mjs",
"description": "JavaScript module",
"category": "Other"
},
{
"extension": "mp3",
"description": "MP3 audio",
"category": "Music"
},
{
"extension": "mp4",
"description": "MP4 video",
"category": "Movie"
},
{
"extension": "mpeg",
"description": "MPEG Video",
"category": "Movie"
},
{
"extension": "mpkg",
"description": "Apple Installer Package",
"category": "Application"
},
{
"extension": "odp",
"description": "OpenDocument presentation document",
"category": "Presentation"
},
{
"extension": "ods",
"description": "OpenDocument spreadsheet document",
"category": "Document"
},
{
"extension": "odt",
"description": "OpenDocument text document",
"category": "Document"
},
{
"extension": "oga",
"description": "OGG audio",
"category": "Music"
},
{
"extension": "ogv",
"description": "OGG video",
"category": "Movie"
},
{
"extension": "ogx",
"description": "OGG",
"category": "Other"
},
{
"extension": "opus",
"description": "Opus audio",
"category": "Music"
},
{
"extension": "otf",
"description": "OpenType font",
"category": "Other"
},
{
"extension": "png",
"description": "Portable Network Graphics",
"category": "Image"
},
{
"extension": "pdf",
"description": "Adobe Portable Document Format (PDF)",
"category": "PDF"
},
{
"extension": "php",
"description": "Hypertext Preprocessor (Personal Home Page)",
"category": "Other"
},
{
"extension": "ppt",
"description": "Microsoft PowerPoint",
"category": "Presentation"
},
{
"extension": "pptx",
"description": "Microsoft PowerPoint (OpenXML)",
"category": "Presentation"
},
{
"extension": "rar",
"description": "RAR archive",
"category": "Other"
},
{
"extension": "rtf",
"description": "Rich Text Format (RTF)",
"category": "Document"
},
{
"extension": "sh",
"description": "Bourne shell script",
"category": "Executable"
},
{
"extension": "svg",
"description": "Scalable Vector Graphics (SVG)",
"category": "Image"
},
{
"extension": "tar",
"description": "Tape Archive (TAR)",
"category": "Other"
},
{
"extension": "tif",
"description": "Tagged Image File Format (TIFF)",
"category": "Image"
},
{
"extension": "tiff",
"description": "Tagged Image File Format (TIFF)",
"category": "Image"
},
{
"extension": "ts",
"description": "MPEG transport stream",
"category": "Movie"
},
{
"extension": "ttf",
"description": "TrueType Font",
"category": "Other"
},
{
"extension": "txt",
"description": "Text, (generally ASCII or ISO 8859-n)",
"category": "Text"
},
{
"extension": "vsd",
"description": "Microsoft Visio",
"category": "Application"
},
{
"extension": "wav",
"description": "Waveform Audio Format",
"category": "Music"
},
{
"extension": "weba",
"description": "WEBM audio",
"category": "Music"
},
{
"extension": "webm",
"description": "WEBM video",
"category": "Movie"
},
{
"extension": "webp",
"description": "WEBP image",
"category": "Image"
},
{
"extension": "woff",
"description": "Web Open Font Format (WOFF)",
"category": "Other"
},
{
"extension": "woff2",
"description": "Web Open Font Format (WOFF)",
"category": "Other"
},
{
"extension": "xhtml",
"description": "XHTML",
"category": "Other"
},
{
"extension": "xls",
"description": "Microsoft Excel",
"category": "Document"
},
{
"extension": "xlsx",
"description": "Microsoft Excel (OpenXML)",
"category": "Document"
},
{
"extension": "xml",
"description": "XML",
"category": "Document"
},
{
"extension": "xul",
"description": "XUL",
"category": "Application"
},
{
"extension": "zip",
"description": "ZIP archive",
"category": "Application"
},
{
"extension": "3gp",
"description": "3GPP audio/video container",
"category": "Movie"
},
{
"extension": "3g2",
"description": "3GPP2 audio/video container",
"category": "Movie"
},
{
"extension": "7z",
"description": "7-zip archive",
"category": "Application"
}
]

15
gbot.cmd Normal file
View file

@ -0,0 +1,15 @@
@ECHO off
ECHO General Bots Command Line
IF EXIST node_modules goto COMPILE
ECHO Installing Packages for the first time use (it may take several minutes)...
CALL npm install --silent
:COMPILE
IF EXIST dist goto ALLSET
ECHO Compiling...
npm run build
:ALLSET
npm run start

2
gbot.sh Executable file
View file

@ -0,0 +1,2 @@
echo Starting General Bots...
npm run start

11
greenkeeper.json Normal file
View file

@ -0,0 +1,11 @@
{
"groups": {
"default": {
"packages": [
"package.json",
"packages/default.gbtheme/package.json",
"packages/default.gbui/package.json"
]
}
}
}

BIN
logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8 KiB

View file

@ -1,51 +1,341 @@
{ {
"name": "botserver", "name": "botserver",
"version": "0.0.11", "version": "3.1.0",
"description": "General Bots Community Edition open-core server.", "type": "module",
"author": "me@rodrigorodriguez.com", "description": "General Bot Community Edition open-core server.",
"license": "AGPL-3.0", "main": "./boot.mjs",
"main": "./src/app.ts", "bugs": "https://github.com/pragmatismo-io/BotServer/issues",
"homepage": "http://pragmatismo.io", "homepage": "https://github.com/pragmatismo-io/BotServer/#readme",
"scripts": { "contributors": [
"clean": "rimraf dist", "Rodrigo Rodriguez <me@rodrigorodriguez.com>",
"start": "node ./dist/src/app.js", "João Ferreira <joao.parana@gmail.com>",
"startIde": "npm-run-all clean --parallel watch:build watch:server --print-label", "Jorge Ramos <jramos@pobox.com>",
"watch:build": "tsc --watch", "PH <ph.an@outlook.com>",
"watch:server": "nodemon './dist/index.js' --watch './dist'", "Dário Vieira <dario.junior3@gmail.com>",
"test": "mocha -r ts-node/register src/**/*.test.ts", "Alan Perdomo <alanperdomo@hotmail.com>"
"build-docs": "typedoc --options typedoc.json src/"
}, ],
"engines": { "engines": {
"node": ">=8.9.4" "node": "=21.7.3"
},
"license": "AGPL-3.0",
"preferGlobal": true,
"private": false,
"bin": {
"gbot": "./boot.cjs"
},
"readme": "README.md",
"repository": {
"type": "git",
"url": "https://github.com/GeneralBots/BotServer.git"
},
"scripts": {
"clean": "shx rm -rf node_modules/ dist/ docs/reference",
"tslint": "tslint --fix ./src/*.ts ./packages/**/*.ts -t verbose",
"build": "npm install && npm run build-server && npm run build-gbui",
"build-server": "tsc",
"build-gbui": "cd packages/default.gbui && echo SKIP_PREFLIGHT_CHECK=true >.env && npm install && npm run build",
"build-docs": "typedoc --options typedoc.json src/",
"test": "vitest",
"start": "NODE_NO_WARNINGS=1 node ./boot.mjs --loader ts-node/esm --require ./suppress-node-warnings.cjs",
"debug": "NODE_NO_WARNINGS=1 node ./boot.mjs --loader ts-node/esm --require ./suppress-node-warnings.cjs --inspect",
"reverse-proxy": "node_modules/.bin/ngrok http 4242",
"watch:build": "tsc --watch",
"posttypedoc": "shx cp .nojekyll docs/reference/.nojekyll",
"ban": "ban",
"issues": "git-issues",
"license": "license-checker --production --onlyunknown --csv",
"pretty": "prettier-standard 'src/*.ts' 'packages/**/*.ts'",
"secure": "nsp check",
"size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";",
"unused-deps": "dependency-check --unused --no-dev ./package.json",
"travis-deploy-once": "travis-deploy-once --pro",
"semantic-release": "semantic-release",
"commit": "git-cz"
},
"jest": {
"workerIdleMemoryLimit": "4096MB",
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
]
}, },
"dependencies": { "dependencies": {
"async": "^1.5.2", "@azure/arm-appservice": "13.0.3",
"botbuilder": "^3.14.0", "@azure/arm-cognitiveservices": "7.3.1",
"chokidar": "^2.0.2", "@azure/arm-resources": "5.1.0",
"csv-parse": "^2.2.0", "@azure/arm-search": "3.0.1",
"dotenv-extended": "^1.0.4", "@azure/arm-sql": "9.0.1",
"express": "^4.16.2", "@azure/arm-subscriptions": "5.1.0",
"fs-walk": "0.0.1", "@azure/cognitiveservices-computervision": "8.2.0",
"marked": "^0.3.12", "@azure/keyvault-keys": "4.6.0",
"reflect-metadata": "^0.1.12", "@azure/ms-rest-js": "2.6.2",
"request-promise-native": "^1.0.5", "@azure/msal-node": "1.14.3",
"sequelize": "^4.37.6", "@azure/search-documents": "12.0.0",
"sequelize-typescript": "^0.6.3", "@azure/storage-blob": "12.17.0",
"sqlite3": "^3.1.13", "@google-cloud/pubsub": "3.2.1",
"tedious": "^2.1.1", "@google-cloud/translate": "7.0.4",
"url-join": "^4.0.0", "@hubspot/api-client": "7.1.2",
"wait-until": "0.0.2", "@koa/cors": "4.0.0",
"winston": "^2.4.0" "@langchain/community": "^0.0.36",
"@langchain/openai": "^0.0.15",
"@microsoft/microsoft-graph-client": "3.0.4",
"@nlpjs/basic": "4.26.1",
"@nosferatu500/textract": "3.1.2",
"@push-rpc/core": "1.8.2",
"@push-rpc/http": "1.8.2",
"@push-rpc/openapi": "^1.9.0",
"@push-rpc/websocket": "1.8.2",
"@semantic-release/changelog": "5.0.1",
"@semantic-release/exec": "5.0.0",
"@semantic-release/git": "9.0.0",
"@sendgrid/mail": "7.7.0",
"@sequelize/core": "7.0.0-alpha.29",
"@types/node": "18.11.9",
"@types/validator": "13.7.10",
"adm-zip": "0.5.9",
"alasql": "2.1.6",
"any-shell-escape": "0.1.1",
"arraybuffer-to-buffer": "0.0.7",
"async-mutex": "0.4.0",
"async-promises": "0.2.3",
"async-retry": "1.3.3",
"basic-auth": "2.0.1",
"billboard.js": "3.6.3",
"bluebird": "3.7.2",
"body-parser": "1.20.1",
"botbuilder": "4.18.0",
"botbuilder-adapter-facebook": "1.0.12",
"botbuilder-ai": "4.18.0",
"botbuilder-dialogs": "4.18.0",
"botframework-connector": "4.18.0",
"botlib": "3.0.11",
"c3-chart-maker": "0.2.8",
"cd": "^0.3.3",
"chalk-animation": "^2.0.3",
"chatgpt": "2.4.2",
"chrome-remote-interface": "0.31.3",
"cli-progress": "3.11.2",
"cli-spinner": "0.2.10",
"core-js": "3.26.1",
"data-forge": "1.9.6",
"date-diff": "1.0.2",
"docximager": "0.0.4",
"docxtemplater": "3.9.7",
"dotenv-extended": "2.9.0",
"dynamics-web-api": "1.7.6",
"exceljs": "4.3.0",
"express": "4.18.2",
"express-remove-route": "1.0.0",
"ffmpeg-static": "5.1.0",
"get-image-colors": "^4.0.1",
"google-libphonenumber": "3.2.31",
"googleapis": "126.0.1",
"hnswlib-node": "^1.4.2",
"http-proxy": "1.18.1",
"ibm-watson": "7.1.2",
"iso-639-1": "3.1.1",
"join-images-updated": "1.1.11",
"js-md5": "0.8.3",
"json-schema-to-zod": "^2.0.14",
"just-indent": "0.0.1",
"keyv": "4.5.2",
"koa": "2.13.4",
"koa-body": "6.0.1",
"koa-router": "12.0.0",
"langchain": "0.1.25",
"language-tags": "^1.0.9",
"line-replace": "2.0.1",
"lodash": "4.17.21",
"lunary": "^0.6.16",
"luxon": "3.1.0",
"mammoth": "1.7.0",
"mariadb": "3.2.2",
"mime-types": "2.1.35",
"moment": "1.3.0",
"ms-rest-azure": "3.0.0",
"nexmo": "2.9.1",
"ngrok": "5.0.0-beta.2",
"node-cron": "3.0.2",
"node-html-parser": "6.1.5",
"node-nlp": "4.26.1",
"node-tesseract-ocr": "2.2.1",
"npm": "9.6.1",
"open": "8.4.0",
"open-docxtemplater-image-module": "1.0.3",
"openai": "4.6.0",
"pdf-extraction": "1.0.2",
"pdf-parse": "1.1.1",
"pdf-to-png-converter": "3.2.0",
"pdfjs-dist": "4.0.379",
"pdfkit": "0.13.0",
"phone": "3.1.30",
"pizzip": "3.1.3",
"pptxtemplater": "1.0.5",
"pragmatismo-io-framework": "1.1.1",
"prism-media": "1.3.4",
"public-ip": "6.0.1",
"punycode": "2.1.1",
"puppeteer": "19.8.0",
"puppeteer-extra": "3.3.4",
"puppeteer-extra-plugin-minmax": "1.1.2",
"puppeteer-extra-plugin-stealth": "2.11.1",
"qr-scanner": "1.4.2",
"qrcode": "1.5.1",
"qrcode-terminal": "0.12.0",
"readline": "1.3.0",
"reflect-metadata": "0.1.13",
"rimraf": "3.0.2",
"safe-buffer": "5.2.1",
"scanf": "1.1.2",
"sequelize": "6.28.2",
"sequelize-cli": "6.6.0",
"sequelize-typescript": "2.1.5",
"sharp": "0.33.4",
"simple-git": "3.16.0",
"speakingurl": "14.0.1",
"ssr-for-bots": "1.0.1-c",
"strict-password-generator": "1.1.2",
"swagger-client": "3.18.5",
"swagger-ui-dist": "^5.11.0",
"tabulator-tables": "5.4.2",
"tedious": "15.1.2",
"textract": "2.5.0",
"twilio": "^4.23.0",
"twitter-api-v2": "1.12.9",
"typescript": "4.9.5",
"url-join": "5.0.0",
"vhost": "3.0.2",
"vm2": "3.9.11",
"vm2-process": "2.1.1",
"walk-promise": "0.2.0",
"washyourmouthoutwithsoap": "1.0.2",
"whatsapp-cloud-api": "0.3.1",
"whatsapp-web.js": "https://github.com/Julzk/whatsapp-web.js/tarball/jkr_hotfix_7",
"winston": "3.8.2",
"ws": "8.14.2",
"yarn": "1.22.19",
"zod-to-json-schema": "^3.22.4"
}, },
"devDependencies": { "devDependencies": {
"@types/azure": "^0.9.19", "@types/qrcode": "1.5.0",
"@types/chai": "4.0.4", "@types/url-join": "4.0.1",
"@types/mocha": "2.2.43", "ban-sensitive-files": "1.9.18",
"chai": "^4.1.2", "commitizen": "4.2.2",
"mocha": "^3.5.3", "cz-conventional-changelog": "3.3.0",
"mocha-typescript": "^1.1.12", "dependency-check": "4.1.0",
"ts-node": "3.3.0", "git-issues": "1.0.0",
"typedoc": "^0.10.0", "license-checker": "25.0.1",
"typescript": "2.7.2" "prettier-standard": "15.0.1",
"semantic-release": "17.2.4",
"simple-commit-message": "4.0.13",
"super-strong-password-generator": "2.0.2",
"super-strong-password-generator-es": "2.0.2",
"travis-deploy-once": "5.0.11",
"tslint": "6.1.3",
"vitest": "^1.3.0"
},
"optionalDependencies": {
"@img/sharp-win32-x64": "0.33.4",
"@img/sharp-linux-arm": "0.33.4"
},
"eslintConfig": {
"env": {
"node": true,
"es6": true,
"mocha": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2017
},
"rules": {
"indent": "off",
"linebreak-style": [
"warn",
"unix"
],
"no-unused-vars": [
"warn"
],
"no-undef": [
"warn"
],
"no-console": [
"warn"
],
"no-case-declarations": [
"warn"
],
"no-extra-semi": [
"warn"
],
"no-unreachable": [
"warn"
],
"no-redeclare": [
"warn"
],
"no-useless-escape": [
"warn"
],
"no-constant-condition": [
"warn"
]
}
},
"release": {
"tagFormat": "${version}",
"debug": true,
"branches": [
"main"
],
"verifyConditions": [
"@semantic-release/github"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog"
],
"prepare": [
"@semantic-release/npm",
{
"path": "@semantic-release/exec",
"cmd": "git status"
},
"@semantic-release/changelog",
{
"path": "@semantic-release/git",
"assets": [
"package.json",
"CHANGELOG.md"
]
}
],
"publish": [
"@semantic-release/npm",
"@semantic-release/github"
],
"analyzeCommits": "simple-commit-message"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
},
"pre-git": {
"commit-msg": "simple",
"pre-commit": [],
"pre-push": [],
"post-commit": [],
"post-checkout": [],
"post-merge": []
}
} }
} }

View file

@ -0,0 +1,457 @@
/*****************************************************************************\
| ® |
| |
| |
| |
| |
| |
| General Bots Copyright (c) pragmatismo.cloud. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of pragmatismo.cloud. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
/**
* @fileoverview General Bots server core.
*/
'use strict';
import crypto from 'crypto';
import urlJoin from 'url-join';
import { WaterfallDialog } from 'botbuilder-dialogs';
import { GBMinInstance, IGBDialog } from 'botlib';
import { GBDeployer } from '../../core.gbapp/services/GBDeployer.js';
import { GBImporter } from '../../core.gbapp/services/GBImporterService.js';
import { Messages } from '../strings.js';
import { GBAdminService } from '../services/GBAdminService.js';
import { CollectionUtil } from 'pragmatismo-io-framework';
import { SecService } from '../../security.gbapp/services/SecService.js';
import { GBConfigService } from '../../core.gbapp/services/GBConfigService.js';
/**
* Dialogs for administration tasks.
*/
export class AdminDialog extends IGBDialog {
public static isIntentYes(locale, utterance) {
return utterance.toLowerCase().match(Messages[locale].affirmative_sentences);
}
public static isIntentNo(locale, utterance) {
return utterance.toLowerCase().match(Messages[locale].negative_sentences);
}
/**
* Setup dialogs flows and define services call.
*
* @param bot The bot adapter.
* @param min The minimal bot instance data.
*/
public static setup(min: GBMinInstance) {
// Setup services.
const importer = new GBImporter(min.core);
const deployer = new GBDeployer(min.core, importer);
AdminDialog.setupSecurityDialogs(min);
min.dialogs.add(
new WaterfallDialog('/admin-auth', [
async step => {
if (step.context.activity.channelId !== 'msteams' && process.env.ENABLE_AUTH) {
return await step.beginDialog('/auth');
} else {
return await step.next(step.options);
}
},
async step => {
const locale = step.context.activity.locale;
const prompt = Messages[locale].authenticate;
return await min.conversationalService.prompt(min, step, prompt);
},
async step => {
const locale = step.context.activity.locale;
const sensitive = step.context.activity['originalText'];
if (sensitive === min.instance.adminPass) {
await min.conversationalService.sendText(min, step, Messages[locale].welcome);
return await step.endDialog(true);
} else {
await min.conversationalService.sendText(min, step, Messages[locale].wrong_password);
return await step.replaceDialog('/admin-auth');
}
}
])
);
min.dialogs.add(
new WaterfallDialog('/admin', [
async step => {
if (step.context.activity.channelId !== 'msteams' && process.env.ENABLE_AUTH) {
return await step.beginDialog('/auth');
} else {
return await step.next(step.options);
}
},
async step => {
const locale = step.context.activity.locale;
const prompt = Messages[locale].authenticate;
return await min.conversationalService.prompt(min, step, prompt);
},
async step => {
const locale = step.context.activity.locale;
const sensitive = step.context.activity['originalText'];
if (sensitive === min.instance.adminPass) {
await min.conversationalService.sendText(min, step, Messages[locale].welcome);
return await min.conversationalService.prompt(min, step, Messages[locale].which_task);
} else {
await min.conversationalService.sendText(min, step, Messages[locale].wrong_password);
return await step.endDialog();
}
},
async step => {
const locale: string = step.context.activity.locale;
// tslint:disable-next-line:no-unsafe-any
const text: string = step.context.activity['originalText'];
const cmdName = text.split(' ')[0];
await min.conversationalService.sendText(min, step, Messages[locale].working(cmdName));
let unknownCommand = false;
try {
if (text === 'quit') {
return await step.replaceDialog('/');
} else if (cmdName === 'setupSecurity') {
return await step.beginDialog('/setupSecurity');
} else {
unknownCommand = true;
}
if (unknownCommand) {
await min.conversationalService.sendText(min, step, Messages[locale].unknown_command);
} else {
await min.conversationalService.sendText(min, step, Messages[locale].finished_working);
}
} catch (error) {
await min.conversationalService.sendText(min, step, error.message ? error.message : error);
}
await step.replaceDialog('/ask', { isReturning: true });
}
])
);
min.dialogs.add(
new WaterfallDialog('/install', [
async step => {
if (step.context.activity.channelId !== 'msteams' && process.env.ENABLE_AUTH) {
return await step.beginDialog('/auth');
} else {
return await step.next(step.options);
}
},
async step => {
step.activeDialog.state.options.args = (step.options as any).args;
if (step.activeDialog.state.options.confirm) {
return await step.next('sim');
} else {
const locale = step.context.activity.locale;
return await min.conversationalService.prompt(min, step, Messages[locale].publish_type_yes);
}
},
async step => {
const locale = step.context.activity.locale;
// If the user says yes, starts publishing.
if (AdminDialog.isIntentYes(locale, step.result)) {
const list = min.core.getParam(min.instance, '.gbapp List', null);
const items = list ? list.split(';') : [];
step.activeDialog.state.options.args;
for (let i = 0; i < items.length; i++) {
for (let j = 0; j < min.appPackages.length; j++) {
if (items[i] === min.appPackages[j]['name']) {
const element = min.appPackages[i];
await element.onExchangeData(min, 'install', null);
break;
}
}
}
} else {
await min.conversationalService.sendText(min, step, Messages[locale].publish_canceled);
}
}
])
);
min.dialogs.add(
new WaterfallDialog('/logs', [
async step => {
if (step.context.activity.channelId !== 'msteams' && process.env.ENABLE_AUTH) {
return await step.beginDialog('/auth');
} else {
return await step.next(step.options);
}
},
async step => {
const logs = await min.core['getLatestLogs']();
await min.conversationalService.sendText(min, step, logs);
return await step.replaceDialog('/ask', { isReturning: true });
}
]));
min.dialogs.add(
new WaterfallDialog('/publish', [
async step => {
if (step.context.activity.channelId !== 'msteams' && process.env.ENABLE_AUTH) {
return await step.beginDialog('/auth');
} else {
return await step.next(step.options);
}
},
async step => {
step.activeDialog.state.options.confirm = true; // Feature removed.
if (step.activeDialog.state.options.confirm || process.env.ADMIN_OPEN_PUBLISH === 'true') {
return await step.next('sim');
} else {
const locale = step.context.activity.locale;
return await min.conversationalService.prompt(min, step, Messages[locale].publish_type_yes);
}
},
async step => {
const locale = step.context.activity.locale;
// If the user says yes, starts publishing.
if (AdminDialog.isIntentYes(locale, step.result)) {
let from = step.context.activity.from.id;
let canPublish: Boolean;
if (step.activeDialog.state.options.firstTime) {
canPublish = true;
} else {
canPublish = AdminDialog.canPublish(min, from) || process.env.ADMIN_OPEN_PUBLISH === 'true';
}
if (!canPublish) {
await step.beginDialog('/admin-auth');
} else {
await step.next(true);
}
} else {
await min.conversationalService.sendText(min, step, Messages[locale].publish_canceled);
}
},
async step => {
const locale = step.context.activity.locale;
if (!step.result) {
await min.conversationalService.sendText(min, step, Messages[locale].publish_must_be_admin);
return step.endDialog();
}
const botId = min.instance.botId;
await min.conversationalService.sendText(min, step, Messages[locale].working('Publishing'));
step.activeDialog.state.options.args = (step.options as any).args;
const filename = step.activeDialog.state.options.args
? step.activeDialog.state.options.args.split(' ')[0]
: null;
const packages = [];
let skipError = false;
if (filename === null || filename === '') {
await min.conversationalService.sendText(min, step, `Starting publishing for ${botId} packages...`);
packages.push(`${botId}.gbot`);
packages.push(`${botId}.gbtheme`);
packages.push(`${botId}.gbkb`);
packages.push(`${botId}.gbdialog`);
skipError = true;
} else {
packages.push(filename);
}
await CollectionUtil.asyncForEach(packages, async packageName => {
let cmd1;
if (
packageName.toLowerCase() === 'gbdialog' ||
packageName.toLowerCase() === 'gbkb' ||
packageName.toLowerCase() === 'gbot' ||
packageName.toLowerCase() === 'gbtheme'
) {
packageName = `${min.botId}.${packageName}`;
}
if (packageName.indexOf('.') !== -1) {
cmd1 = `deployPackage ${process.env.STORAGE_SITE} /${process.env.STORAGE_LIBRARY}/${botId}.gbai/${packageName}`;
} else {
cmd1 = `deployPackage ${packageName}`;
}
if (
(await (deployer as any).getStoragePackageByName(min.instance.instanceId, packageName)) !== null &&
!process.env.DONT_DOWNLOAD
) {
const cmd2 = `undeployPackage ${packageName}`;
await GBAdminService.undeployPackageCommand(cmd2, min);
}
let sec = new SecService();
const member = step.context.activity.from;
const user = await sec.ensureUser(
min,
member.id,
member.name,
'',
'web',
member.name,
null
);
await GBAdminService.deployPackageCommand(min, user, cmd1, deployer);
});
await min.conversationalService.sendText(min, step, `Training is finished.`);
if (!step.activeDialog.state.options.confirm) {
return await step.replaceDialog('/ask', { isReturning: true });
} else {
return await step.endDialog();
}
}
])
);
}
/**
* Check if the specified phone can receive a message by running
* the /broadcast command with specific phone numbers.
* @param phone Phone number to check (eg.: +5521900002233)
*/
public static canPublish(min: GBMinInstance, phone: string): Boolean {
if (process.env.SECURITY_CAN_PUBLISH !== undefined) {
let list = process.env.SECURITY_CAN_PUBLISH.split(';');
const canPublish = min.core.getParam(min.instance, 'Can Publish', null);
if (canPublish) {
list = list.concat(canPublish.split(';'));
}
let result = list.includes(phone);
if (!result && min.instance.params) {
const params = JSON.parse(min.instance.params);
if (params) {
return list.includes(params['Can Publish']);
}
}
return result;
}
}
private static setupSecurityDialogs(min: GBMinInstance) {
min.dialogs.add(
new WaterfallDialog('/setupSecurity', [
async step => {
const tokenName = step.activeDialog.state.tokenName = step.options['args'];
if (tokenName) {
step.activeDialog.state.clientId = min.core.getParam<string>(min.instance, `${tokenName} Client ID`, null),
step.activeDialog.state.host = min.core.getParam<string>(min.instance, `${tokenName} Host`, null),
step.activeDialog.state.tenant = min.core.getParam<string>(min.instance, `${tokenName} Tenant`, null)
}
if (step.context.activity.channelId !== 'msteams' && process.env.ENABLE_AUTH) {
return await step.beginDialog('/auth');
} else {
return await step.next(step.options);
}
},
async step => {
if (step.activeDialog.state.tokenName) {
return await step.next(step.options);
}
const locale = step.context.activity.locale;
const prompt = Messages[locale].enter_authenticator_tenant;
return await min.conversationalService.prompt(min, step, prompt);
},
async step => {
if (step.activeDialog.state.tokenName) {
return await step.next(step.options);
}
step.activeDialog.state.authenticatorTenant = step.context.activity['originalText'];
const locale = step.context.activity.locale;
const prompt = Messages[locale].enter_authenticator_authority_host_url;
return await min.conversationalService.prompt(min, step, prompt);
},
async step => {
step.activeDialog.state.authenticatorAuthorityHostUrl = step.context.activity['originalText'];
const tokenName = step.activeDialog.state.tokenName;
if (!tokenName) {
min.instance.authenticatorAuthorityHostUrl = step.activeDialog.state.authenticatorAuthorityHostUrl;
min.instance.authenticatorTenant = step.activeDialog.state.authenticatorTenant;
await min.adminService.updateSecurityInfo(
min.instance.instanceId,
tokenName ? step.activeDialog.state.tenant : step.activeDialog.state.authenticatorTenant,
tokenName ? step.activeDialog.state.host : step.activeDialog.state.authenticatorAuthorityHostUrl
);
}
const locale = step.context.activity.locale;
const buf = Buffer.alloc(16);
const state = `${min.instance.instanceId}${crypto.randomFillSync(buf).toString('hex')}`;
min.adminService.setValue(min.instance.instanceId, `${tokenName}AntiCSRFAttackState`, state);
const redirectUri = urlJoin(process.env.BOT_URL, min.instance.botId,
tokenName ? `/token?value=${tokenName}` : '/token');
const scope = tokenName ? '' : 'https://graph.microsoft.com/.default';
const host = tokenName ? step.activeDialog.state.host : 'https://login.microsoftonline.com'
const tenant = tokenName ? step.activeDialog.state.tenant : min.instance.authenticatorTenant;
const clientId = tokenName ? step.activeDialog.state.clientId : (min.instance.marketplaceId ?
min.instance.marketplaceId : GBConfigService.get('MARKETPLACE_ID'));
const oauth2 = tokenName ? 'oauth' : 'oauth2';
const url = `${host}/${tenant}/${oauth2}/authorize?client_id=${clientId}&response_type=code&redirect_uri=${redirectUri}&scope=${scope}&state=${state}&response_mode=query`;
await min.conversationalService.sendText(min, step, Messages[locale].consent(url));
return await step.replaceDialog('/ask', { isReturning: true });
}
])
);
}
}

View file

@ -0,0 +1,73 @@
/*****************************************************************************\
| ® |
| |
| |
| |
| |
| |
| General Bots Copyright (c) pragmatismo.cloud. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY, without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of pragmatismo.cloud. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
/**
* @fileoverview General Bots server core.
*/
'use strict';
import { GBDialogStep, GBLog, GBMinInstance, IGBCoreService, IGBPackage } from 'botlib';
import { Sequelize } from 'sequelize-typescript';
import { AdminDialog } from './dialogs/AdminDialog.js';
import { GuaribasAdmin } from './models/AdminModel.js';
import { GBLogEx } from '../core.gbapp/services/GBLogEx.js';
/**
* The package for admin.gbapp.
*/
export class GBAdminPackage implements IGBPackage {
public sysPackages: IGBPackage[];
public async getDialogs (min: GBMinInstance) {
GBLogEx.verbose(min,`getDialogs called.`);
}
public async unloadPackage (core: IGBCoreService): Promise<void> {
GBLog.verbose(`unloadPackage called.`);
}
public async unloadBot (min: GBMinInstance): Promise<void> {
GBLogEx.verbose(min,`unloadBot called.`);
}
public async onNewSession (min: GBMinInstance, step: GBDialogStep): Promise<void> {
GBLogEx.verbose(min, `onNewSession called.`);
}
public async onExchangeData (min: GBMinInstance, kind: string, data: any) {
GBLogEx.verbose(min,`onExchangeData called.`);
}
public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise<void> {
core.sequelize.addModels([GuaribasAdmin]);
}
public async loadBot (min: GBMinInstance): Promise<void> {
AdminDialog.setup(min);
}
}

View file

@ -1,13 +1,11 @@
/*****************************************************************************\ /*****************************************************************************\
| ( )_ _ | | ® |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ | | |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' _ `\ /'_`\ | | |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| ( ) |( (_) ) | | |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' | | |
| | | ( )_) | |
| (_) \___/' |
| | | |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. | | General Bots Copyright (c) pragmatismo.cloud. All rights reserved. |
| Licensed under the AGPL-3.0. | | Licensed under the AGPL-3.0. |
| | | |
| According to our dual licensing model, this program can be used either | | According to our dual licensing model, this program can be used either |
@ -19,49 +17,44 @@
| in the LICENSE file you have received along with this program. | | in the LICENSE file you have received along with this program. |
| | | |
| This program is distributed in the hope that it will be useful, | | This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of | | but WITHOUT ANY WARRANTY, without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. | | GNU Affero General Public License for more details. |
| | | |
| "General Bots" is a registered trademark of Pragmatismo.io. | | "General Bots" is a registered trademark of pragmatismo.cloud. |
| The licensing of the program under the AGPLv3 does not imply a | | The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in | | trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. | | our trademarks remain entirely with us. |
| | | |
\*****************************************************************************/ \*****************************************************************************/
"use strict"; /**
* @fileoverview General Bots server core.
*/
const UrlJoin = require("url-join"); 'use strict';
import { Column, CreatedAt, DataType, Model, Table, UpdatedAt } from 'sequelize-typescript';
import { GBMinInstance, IGBPackage, IGBCoreService } from "botlib"; /**
import { Session } from 'botbuilder'; * General settings store.
import { Sequelize } from "sequelize-typescript"; */
import { GuaribasUser, GuaribasGroup, GuaribasUserGroup } from "./models"; @Table
export class GuaribasAdmin extends Model<GuaribasAdmin> {
@Column(DataType.INTEGER)
declare instanceId: number;
export class GBSecurityPackage implements IGBPackage { @Column(DataType.STRING(255))
declare key: string;
loadPackage(core: IGBCoreService, sequelize: Sequelize): void { @Column(DataType.STRING(4000))
core.sequelize.addModels([ declare value: string;
GuaribasGroup,
GuaribasUser, @Column(DataType.DATE)
GuaribasUserGroup @CreatedAt
]); declare createdAt: Date;
}
@Column(DataType.DATE)
unloadPackage(core: IGBCoreService): void { @UpdatedAt
declare updatedAt: Date;
}
loadBot(min: GBMinInstance): void {
}
unloadBot(min: GBMinInstance): void {
}
onNewSession(min: GBMinInstance, session: Session): void {
}
} }

View file

@ -0,0 +1,363 @@
/*****************************************************************************\
| ® |
| |
| |
| |
| |
| |
| General Bots Copyright (c) pragmatismo.cloud. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY, without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of pragmatismo.cloud. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
/**
* @fileoverview General Bots server core.
*/
'use strict';
import { AuthenticationContext, TokenResponse } from 'adal-node';
import { GBError, GBLog, GBMinInstance, IGBAdminService, IGBCoreService, IGBDeployer, IGBInstance } from 'botlib';
import { FindOptions } from 'sequelize/types';
import urlJoin from 'url-join';
import { AzureDeployerService } from '../../azuredeployer.gbapp/services/AzureDeployerService.js';
import { GuaribasInstance } from '../../core.gbapp/models/GBModel.js';
import { GBConfigService } from '../../core.gbapp/services/GBConfigService.js';
import { GBDeployer } from '../../core.gbapp/services/GBDeployer.js';
import { GBImporter } from '../../core.gbapp/services/GBImporterService.js';
import { GBSharePointService } from '../../sharepoint.gblib/services/SharePointService.js';
import { GuaribasAdmin } from '../models/AdminModel.js';
import msRestAzure from 'ms-rest-azure';
import Path from 'path';
import { caseSensitive_Numbs_SpecialCharacters_PW, lowercase_PW } from 'super-strong-password-generator'
import crypto from 'crypto';
import Fs from 'fs';
import { GBServer } from '../../../src/app.js';
import { GuaribasUser } from '../../security.gbapp/models/index.js';
import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js';
import { GBLogEx } from '../../core.gbapp/services/GBLogEx.js';
/**
* Services for server administration.
*/
export class GBAdminService implements IGBAdminService {
public static GB_PROMPT: string = 'GeneralBots: ';
public static masterBotInstanceId = 0;
public static StrongRegex = new RegExp('^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*+_-])(?=.{8,})');
public core: IGBCoreService;
constructor(core: IGBCoreService) {
this.core = core;
}
public static generateUuid(): string {
return crypto.randomUUID();
}
public static getNodeVersion() {
const packageJson = urlJoin(process.cwd(), 'package.json');
const pkg = JSON.parse(Fs.readFileSync(packageJson, 'utf8'));
return pkg.engines.node.replace('=', '');
}
public static async getADALTokenFromUsername(username: string, password: string) {
const credentials = await GBAdminService.getADALCredentialsFromUsername(username, password);
return (credentials as any).tokenCache._entries[0].accessToken;
}
public static async getADALCredentialsFromUsername(username: string, password: string) {
return await msRestAzure.loginWithUsernamePassword(username, password);
}
public static getMobileCode() {
return this.getNumberIdentifier(6);
}
public static getRndPassword(): string {
let password = caseSensitive_Numbs_SpecialCharacters_PW(15);
password = password.replace(/[\@\[\=\:\;\?\"\'\#]/gi, '*');
const removeRepeatedChars = (s, r) => {
let res = '', last = null, counter = 0;
s.split('').forEach(char => {
if (char == last)
counter++;
else {
counter = 0;
last = char;
}
if (counter < r)
res += char;
});
return res;
}
return removeRepeatedChars(password, 1);
}
public static getRndReadableIdentifier(): string {
return lowercase_PW(14);
}
public static getNumberIdentifier(digits: number = 14): string {
if (digits <= 0) {
throw new Error('Number of digits should be greater than 0.');
}
const min = 10 ** (digits - 1);
const max = 10 ** digits - 1;
const randomNumber = Math.floor(Math.random() * (max - min + 1)) + min;
return randomNumber.toString();
}
/**
* @see https://stackoverflow.com/a/52171480
*/
public static getHash(str: string, seed = 0) {
let h1 = 0xdeadbeef ^ seed,
h2 = 0x41c6ce57 ^ seed;
for (let i = 0, ch; i < str.length; i++) {
ch = str.charCodeAt(i);
h1 = Math.imul(h1 ^ ch, 2654435761);
h2 = Math.imul(h2 ^ ch, 1597334677);
}
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
}
public static async undeployPackageCommand(text: string, min: GBMinInstance) {
const packageName = text.split(' ')[1];
const importer = new GBImporter(min.core);
const deployer = new GBDeployer(min.core, importer);
const path = DialogKeywords.getGBAIPath(min.botId, null, packageName);
const localFolder = Path.join('work', path);
await deployer.undeployPackageFromLocalPath(min.instance, localFolder);
}
public static isSharePointPath(path: string) {
return path.indexOf('sharepoint.com') !== -1;
}
public static async deployPackageCommand(min: GBMinInstance, user: GuaribasUser, text: string, deployer: IGBDeployer) {
const packageName = text.split(' ')[1];
if (!this.isSharePointPath(packageName)) {
const additionalPath = GBConfigService.get('ADDITIONAL_DEPLOY_PATH');
if (additionalPath === undefined) {
throw new Error('ADDITIONAL_DEPLOY_PATH is not set and deployPackage was called.');
}
await deployer['deployPackage2'](min, user, urlJoin(additionalPath, packageName));
} else {
const folderName = text.split(' ')[2];
const packageType = Path.extname(folderName).substr(1);
const gbaiPath = DialogKeywords.getGBAIPath(min.instance.botId, packageType, null);
const localFolder = Path.join('work', gbaiPath);
// .gbot packages are handled using storage API, so no download
// of local resources is required.
const gbai = DialogKeywords.getGBAIPath(min.instance.botId);
if (packageType === 'gbkb') {
await deployer['cleanupPackage'](min.instance, packageName);
}
await deployer['downloadFolder'](min,
Path.join('work', `${gbai}`),
Path.basename(localFolder));
await deployer['deployPackage2'](min, user, localFolder);
}
}
public static async rebuildIndexPackageCommand(min: GBMinInstance, deployer: GBDeployer) {
const service = await AzureDeployerService.createInstance(deployer);
const searchIndex = min.instance.searchIndex ? min.instance.searchIndex : GBServer.globals.minBoot.instance.searchIndex;
await deployer.rebuildIndex(
min.instance,
service.getKBSearchSchema(searchIndex)
);
}
public static async syncBotServerCommand(min: GBMinInstance, deployer: GBDeployer) {
const serverName = `${min.instance.botId}-server`;
const service = await AzureDeployerService.createInstance(deployer);
service.syncBotServerRepository(min.instance.botId, serverName);
}
public async setValue(instanceId: number, key: string, value: string) {
const options = <FindOptions>{ where: {} };
options.where = { key: key, instanceId: instanceId };
let admin = await GuaribasAdmin.findOne(options);
if (admin === null) {
admin = new GuaribasAdmin();
admin.key = key;
}
admin.value = value;
admin.instanceId = instanceId;
await admin.save();
}
public async updateSecurityInfo(
instanceId: number,
authenticatorTenant: string,
authenticatorAuthorityHostUrl: string
): Promise<IGBInstance> {
const options = <FindOptions>{ where: {} };
options.where = { instanceId: instanceId };
const item = await GuaribasInstance.findOne(options);
item.authenticatorTenant = authenticatorTenant;
item.authenticatorAuthorityHostUrl = authenticatorAuthorityHostUrl;
return item.save();
}
public async getValue(instanceId: number, key: string): Promise<string> {
const options = <FindOptions>{ where: {} };
options.where = { key: key, instanceId: instanceId };
const obj = await GuaribasAdmin.findOne(options);
return obj.value;
}
public async acquireElevatedToken(instanceId: number, root: boolean = false,
tokenName: string = '',
clientId: string = null,
clientSecret: string = null,
host: string = null,
tenant: string = null
): Promise<string> {
if (root) {
const minBoot = GBServer.globals.minBoot;
instanceId = minBoot.instance.instanceId;
}
GBLogEx.info(instanceId, `Acquiring token for instanceId: ${instanceId} ${tokenName} (root: ${root}).`);
let expiresOnV;
try {
expiresOnV = await this.getValue(instanceId, `${tokenName}expiresOn`);
} catch (error) {
throw new Error(`/setupSecurity is required before running /publish.`);
}
return new Promise<string>(async (resolve, reject) => {
const instance = await this.core.loadInstanceById(instanceId);
const expiresOn = new Date(expiresOnV);
if (expiresOn.getTime() > new Date().getTime()) {
const accessToken = await this.getValue(instanceId, `${tokenName}accessToken`);
resolve(accessToken);
} else {
if (tokenName && !root) {
const refreshToken = await this.getValue(instanceId, `${tokenName}refreshToken`);
let url = urlJoin(
host,
tenant, 'oauth/token');
let buff = new Buffer(`${clientId}:${clientSecret}`);
const base64 = buff.toString('base64');
const options = {
method: 'POST',
headers: {
Accept: '1.0',
Authorization: `Basic ${base64}`,
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
'grant_type': 'refresh_token',
'refresh_token': refreshToken
})
};
const result = await fetch(url, options);
if (result.status != 200) {
const text = await result.text();
throw new Error(`acquireElevatedToken refreshing token: ${result.status}: ${result.statusText} ${text}.`);
}
const text = await result.text();
const token = JSON.parse(text);
// Saves token to the database.
await this.setValue(instanceId, `${tokenName}accessToken`, token['access_token']);
await this.setValue(instanceId, `${tokenName}refreshToken`, token['refresh_token']);
await this.setValue(instanceId, `${tokenName}expiresOn`,
new Date(Date.now() + (token['expires_in'] * 1000)).toString());
await this.setValue(instanceId, `${tokenName}AntiCSRFAttackState`, null);
resolve(token['access_token']);
}
else {
const oauth2 = tokenName ? 'oauth' : 'oauth2';
const authorizationUrl = urlJoin(
tokenName ? host : instance.authenticatorAuthorityHostUrl,
tokenName ? tenant : instance.authenticatorTenant,
`/${oauth2}/authorize`
);
const refreshToken = await this.getValue(instanceId, `${tokenName}refreshToken`);
const resource = tokenName ? '' : 'https://graph.microsoft.com';
const authenticationContext = new AuthenticationContext(authorizationUrl);
authenticationContext.acquireTokenWithRefreshToken(
refreshToken,
tokenName ? clientId : instance.marketplaceId,
tokenName ? clientSecret : instance.marketplacePassword,
resource,
async (err, res) => {
if (err !== null) {
reject(err);
} else {
const token = res as TokenResponse;
try {
await this.setValue(instanceId, `${tokenName}accessToken`, token.accessToken);
await this.setValue(instanceId, `${tokenName}refreshToken`, token.refreshToken);
await this.setValue(instanceId, `${tokenName}expiresOn`, token.expiresOn.toString());
resolve(token.accessToken);
} catch (error) {
reject(err);
}
}
}
);
}
}
});
}
public async publish(min: GBMinInstance, packageName: string, republish: boolean): Promise<void> { }
}

View file

@ -0,0 +1,52 @@
export const Messages = {
'en-US': {
authenticate: 'Please, authenticate:',
welcome: 'Welcome to pragmatismo.cloud GeneralBots Administration.',
which_task: 'Which task do you wanna run now?',
working: command => `I'm working on ${command}...`,
finished_working: 'Done.',
unknown_command: text =>
`Well, but ${text} is not a administrative General Bots command, I will try to search for it.`,
hi: text => `Hello, ${text}.`,
undeployPackage: text => `Undeploying package ${text}...`,
deployPackage: text => `Deploying package ${text}...`,
redeployPackage: text => `Redeploying package ${text}...`,
packageUndeployed: text => `√ Package ${text} undeployed...`,
consent: url => `Please, consent access to this app at: [Microsoft Online](${url}).`,
wrong_password: 'Sorry, wrong password. Please, try again.',
enter_authenticator_tenant: 'Enter the Authenticator Tenant (eg.: domain.onmicrosoft.com):',
enter_authenticator_authority_host_url: 'Enter the Authority Host URL (eg.: https://login.microsoftonline.com): ',
enter_authenticator_client_id: `Enter the Client Id GUID: Get from
[this url](https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredAppsPreview)`,
enter_authenticator_client_secret: 'Enter the Client Secret:',
publish_must_be_admin: 'Seu telefone precisa estar com privilégios administrativos para realizar publicação.',
publish_success: 'Publicação realizada.',
publish_type_yes: 'Por favor, digite *Sim* para continuar com a publicação.',
publish_canceled: 'Publicação cancelada.'
},
'pt-BR': {
authenticate: 'Please, authenticate:',
welcome: 'Welcome to pragmatismo.cloud GeneralBots Administration.',
which_task: 'Which task do you wanna run now?',
working: command => `I'm working on ${command}...`,
finished_working: 'Done.',
unknown_command: text =>
`Well, but ${text} is not a administrative General Bots command, I will try to search for it.`,
hi: text => `Hello, ${text}.`,
undeployPackage: text => `Undeploying package ${text}...`,
deployPackage: text => `Deploying package ${text}...`,
redeployPackage: text => `Redeploying package ${text}...`,
packageUndeployed: text => `Package ${text} undeployed...`,
consent: url => `Please, consent access to this app at: [Microsoft Online](${url}).`,
wrong_password: 'Sorry, wrong password. Please, try again.',
enter_authenticator_tenant: 'Enter the Authenticator Tenant (eg.: domain.onmicrosoft.com):',
enter_authenticator_authority_host_url: 'Enter the Authority Host URL (eg.: https://login.microsoftonline.com): ',
enter_authenticator_client_id: `Enter the Client Id GUID: Get from
[this url](https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredAppsPreview)`,
enter_authenticator_client_secret: 'Enter the Client Secret:',
publish_must_be_admin: 'Seu telefone precisa estar com privilégios administrativos para realizar publicação.',
publish_success: 'Publicação realizada.',
publish_type_yes: 'Por favor, digite *Sim* para continuar com a publicação.',
publish_canceled: 'Publicação cancelada.'
}
};

View file

@ -0,0 +1,68 @@
/*****************************************************************************\
| ® |
| |
| |
| |
| |
| |
| General Bots Copyright (c) pragmatismo.cloud. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY, without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of pragmatismo.cloud. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
/**
* @fileoverview General Bots server core.
*/
'use strict';
import { GBDialogStep, GBLog, GBMinInstance, IGBCoreService, IGBPackage } from 'botlib';
import { Sequelize } from 'sequelize-typescript';
import { GuaribasConversation, GuaribasConversationMessage } from './models/index.js';
/**
* .gblib Package handler.
*/
export class GBAnalyticsPackage implements IGBPackage {
public sysPackages: IGBPackage[];
public async getDialogs (min: GBMinInstance) {
GBLog.verbose(`getDialogs called.`);
}
public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise<void> {
GBLog.verbose(`loadPackage called.`);
core.sequelize.addModels([GuaribasConversation, GuaribasConversationMessage]);
}
public async unloadPackage (core: IGBCoreService): Promise<void> {
GBLog.verbose(`unloadPackage called.`);
}
public async loadBot (min: GBMinInstance): Promise<void> {
GBLog.verbose(`loadBot called.`);
}
public async unloadBot (min: GBMinInstance): Promise<void> {
GBLog.verbose(`unloadBot called.`);
}
public async onNewSession (min: GBMinInstance, step: GBDialogStep): Promise<void> {
GBLog.verbose(`onNewSession called.`);
}
public async onExchangeData (min: GBMinInstance, kind: string, data: any) {
GBLog.verbose(`onExchangeData called.`);
}
}

Some files were not shown because too many files have changed in this diff Show more