2018-04-21 02:59:30 -03:00
|
|
|
/*****************************************************************************\
|
2024-01-09 17:40:48 -03:00
|
|
|
| █████ █████ ██ █ █████ █████ ████ ██ ████ █████ █████ ███ ® |
|
|
|
|
| ██ █ ███ █ █ ██ ██ ██ ██ ██ ██ █ ██ ██ █ █ |
|
|
|
|
| ██ ███ ████ █ ██ █ ████ █████ ██████ ██ ████ █ █ █ ██ |
|
|
|
|
| ██ ██ █ █ ██ █ █ ██ ██ ██ ██ ██ ██ █ ██ ██ █ █ |
|
|
|
|
| █████ █████ █ ███ █████ ██ ██ ██ ██ █████ ████ █████ █ ███ |
|
2018-04-21 02:59:30 -03:00
|
|
|
| |
|
2024-08-17 20:30:00 -03:00
|
|
|
| General Bots Copyright (c) pragmatismo.cloud. All rights reserved. |
|
2018-04-21 02:59:30 -03:00
|
|
|
| Licensed under the AGPL-3.0. |
|
2018-11-11 19:09:18 -02:00
|
|
|
| |
|
2018-04-21 02:59:30 -03:00
|
|
|
| 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, |
|
2018-09-11 19:40:53 -03:00
|
|
|
| but WITHOUT ANY WARRANTY, without even the implied warranty of |
|
2018-04-21 02:59:30 -03:00
|
|
|
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
|
| GNU Affero General Public License for more details. |
|
|
|
|
| |
|
2024-08-17 20:30:00 -03:00
|
|
|
| "General Bots" is a registered trademark of pragmatismo.cloud. |
|
2018-04-21 02:59:30 -03:00
|
|
|
| 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. |
|
|
|
|
| |
|
|
|
|
\*****************************************************************************/
|
|
|
|
|
2018-11-11 19:09:18 -02:00
|
|
|
/**
|
|
|
|
* @fileoverview General Bots server core.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
2018-04-21 02:59:30 -03:00
|
|
|
|
2018-11-12 12:20:44 -02:00
|
|
|
import { BotAdapter } from 'botbuilder';
|
2021-01-05 12:28:40 -03:00
|
|
|
import { WaterfallDialog } from 'botbuilder-dialogs';
|
2024-08-19 23:03:58 -03:00
|
|
|
import { GBMinInstance, IGBDialog } from 'botlib';
|
2022-11-18 22:39:14 -03:00
|
|
|
import { GBServer } from '../../../src/app.js';
|
|
|
|
import { Messages } from '../strings.js';
|
2024-04-21 23:39:39 -03:00
|
|
|
import { GBLogEx } from '../services/GBLogEx.js';
|
2024-08-19 23:03:58 -03:00
|
|
|
import { GBConfigService } from '../services/GBConfigService.js';
|
2018-04-21 02:59:30 -03:00
|
|
|
|
2019-03-09 16:59:31 -03:00
|
|
|
/**
|
|
|
|
* Dialog for Welcoming people.
|
|
|
|
*/
|
2018-04-21 02:59:30 -03:00
|
|
|
export class WelcomeDialog extends IGBDialog {
|
2018-09-09 14:39:37 -03:00
|
|
|
/**
|
|
|
|
* Setup dialogs flows and define services call.
|
2018-09-14 12:56:54 -03:00
|
|
|
*
|
2018-09-09 14:39:37 -03:00
|
|
|
* @param bot The bot adapter.
|
|
|
|
* @param min The minimal bot instance data.
|
|
|
|
*/
|
2022-11-19 23:34:58 -03:00
|
|
|
public static setup (bot: BotAdapter, min: GBMinInstance) {
|
|
|
|
min.dialogs.add(
|
|
|
|
new WaterfallDialog('/', [
|
|
|
|
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 => {
|
|
|
|
if (
|
|
|
|
GBServer.globals.entryPointDialog !== null &&
|
2024-08-19 23:03:58 -03:00
|
|
|
min.instance.botId === GBConfigService.get('BOT_ID') &&
|
2022-11-19 23:34:58 -03:00
|
|
|
step.context.activity.channelId === 'webchat'
|
|
|
|
) {
|
|
|
|
return step.replaceDialog(GBServer.globals.entryPointDialog);
|
|
|
|
}
|
2020-02-25 12:37:10 -03:00
|
|
|
|
2022-11-19 23:34:58 -03:00
|
|
|
const locale = step.context.activity.locale;
|
2018-06-04 05:33:37 -03:00
|
|
|
|
2022-11-19 23:34:58 -03:00
|
|
|
if (
|
2023-02-22 16:06:57 -03:00
|
|
|
// TODO: https://github.com/GeneralBots/BotServer/issues/9 !user.once &&
|
2022-11-19 23:34:58 -03:00
|
|
|
step.context.activity.channelId === 'webchat' &&
|
|
|
|
min.core.getParam<boolean>(min.instance, 'HelloGoodX', true) === 'true'
|
|
|
|
) {
|
2023-02-22 16:06:57 -03:00
|
|
|
// user.once = true;
|
2022-11-19 23:34:58 -03:00
|
|
|
const a = new Date();
|
|
|
|
const date = a.getHours();
|
|
|
|
const msg =
|
|
|
|
date < 12
|
|
|
|
? Messages[locale].good_morning
|
|
|
|
: date < 18
|
2018-09-16 17:00:17 -03:00
|
|
|
? Messages[locale].good_evening
|
|
|
|
: Messages[locale].good_night;
|
2018-09-04 15:09:52 -03:00
|
|
|
|
2022-11-19 23:34:58 -03:00
|
|
|
await min.conversationalService.sendText(min, step, Messages[locale].hi(msg));
|
2020-12-31 15:36:19 -03:00
|
|
|
|
2022-11-19 23:34:58 -03:00
|
|
|
await step.replaceDialog('/ask', { firstTime: true });
|
2018-09-04 15:09:52 -03:00
|
|
|
|
2022-11-19 23:34:58 -03:00
|
|
|
if (
|
|
|
|
step.context.activity !== undefined &&
|
|
|
|
step.context.activity.type === 'message' &&
|
|
|
|
step.context.activity.text !== ''
|
|
|
|
) {
|
2024-04-21 23:39:39 -03:00
|
|
|
GBLogEx.info(min, `/answer being called from WelcomeDialog.`);
|
2022-11-19 23:34:58 -03:00
|
|
|
await step.replaceDialog('/answer', { query: step.context.activity.text });
|
|
|
|
}
|
2018-06-04 20:27:21 -03:00
|
|
|
}
|
2018-11-30 11:55:44 -02:00
|
|
|
|
2022-11-19 23:34:58 -03:00
|
|
|
return await step.next();
|
|
|
|
}
|
|
|
|
])
|
|
|
|
);
|
2018-04-21 02:59:30 -03:00
|
|
|
}
|
|
|
|
}
|