fix(basic.gblib): Upgrade to https://github.com/vasyas/push-rpc from WS to HTTPS.

This commit is contained in:
rodrigorodriguez 2023-03-05 11:09:36 -03:00
parent 39f1907291
commit f3c756b015
5 changed files with 130 additions and 120 deletions

View file

@ -68,9 +68,9 @@
"@microsoft/microsoft-graph-client": "3.0.4", "@microsoft/microsoft-graph-client": "3.0.4",
"@nlpjs/basic": "4.26.1", "@nlpjs/basic": "4.26.1",
"@nosferatu500/textract": "3.1.2", "@nosferatu500/textract": "3.1.2",
"@push-rpc/core": "^1.5.7", "@push-rpc/core": "1.1.5",
"@push-rpc/http": "^1.5.7", "@push-rpc/http": "1.1.5",
"@push-rpc/websocket": "^1.5.7", "@push-rpc/websocket": "1.1.5",
"@semantic-release/changelog": "5.0.1", "@semantic-release/changelog": "5.0.1",
"@semantic-release/exec": "5.0.0", "@semantic-release/exec": "5.0.0",
"@semantic-release/git": "9.0.0", "@semantic-release/git": "9.0.0",
@ -165,7 +165,6 @@
"textract": "2.5.0", "textract": "2.5.0",
"twitter-api-v2": "1.12.9", "twitter-api-v2": "1.12.9",
"typescript": "4.9.5", "typescript": "4.9.5",
"typescript-rest-rpc": "1.0.7",
"url-join": "5.0.0", "url-join": "5.0.0",
"vbscript-to-typescript": "1.0.8", "vbscript-to-typescript": "1.0.8",
"vhost": "3.0.2", "vhost": "3.0.2",

View file

@ -36,7 +36,7 @@
'use strict'; 'use strict';
import { GBDialogStep, GBLog, GBMinInstance, IGBCoreService, IGBPackage } from 'botlib'; import { GBDialogStep, GBLog, GBMinInstance, IGBCoreService, IGBInstance, IGBPackage } from 'botlib';
import { GuaribasSchedule } from '../core.gbapp/models/GBModel.js'; import { GuaribasSchedule } from '../core.gbapp/models/GBModel.js';
import { Sequelize } from 'sequelize-typescript'; import { Sequelize } from 'sequelize-typescript';
import { DialogKeywords } from './services/DialogKeywords.js'; import { DialogKeywords } from './services/DialogKeywords.js';
@ -45,38 +45,38 @@ import { WebAutomationServices } from './services/WebAutomationServices.js';
import { ImageProcessingServices } from './services/ImageProcessingServices.js'; import { ImageProcessingServices } from './services/ImageProcessingServices.js';
import { DebuggerService } from './services/DebuggerService.js'; import { DebuggerService } from './services/DebuggerService.js';
import Koa from 'koa'; import Koa from 'koa';
import {createRpcServer, createRpcClient} from "@push-rpc/core" import { createRpcServer, createRpcClient } from '@push-rpc/core';
import {createKoaHttpMiddleware, createExpressHttpMiddleware, createHttpClient} from "@push-rpc/http" import { createHttpKoaMiddleware, createHttpClient } from '@push-rpc/http';
import { HttpServerOptions } from '@push-rpc/http/dist/server.js';
import { GBServer } from '../../src/app.js'; import { GBServer } from '../../src/app.js';
const app = new Koa(); const app = new Koa();
import {SocketServer} from "@push-rpc/core" import { SocketServer } from '@push-rpc/core';
import * as koaBody from "koa-body" import * as koaBody from 'koa-body';
import { GBVMService } from './services/GBVMService.js';
import { GBLogEx } from '../core.gbapp/services/GBLogEx.js';
import { CollectionUtil } from 'pragmatismo-io-framework';
export function createKoaHttpServer( export function createKoaHttpServer(
port: number, port: number,
getRemoteId: (ctx: Koa.Context) => string getRemoteId: (ctx: Koa.Context) => string,
opts: Partial<HttpServerOptions> = {}
): SocketServer { ): SocketServer {
const {onError, onConnection, middleware} = createKoaHttpMiddleware(getRemoteId) const { onError, onConnection, middleware } = createHttpKoaMiddleware(getRemoteId, opts);
const app = new Koa() const app = new Koa();
app.use(koaBody.koaBody({multipart: true})) app.use(koaBody.koaBody({ multipart: true }));
app.use(middleware) app.use(middleware);
const server = app.listen(port) const server = app.listen(port);
return { return {
onError, onError,
onConnection, onConnection,
close(cb) { close(cb) {
server.close(cb) server.close(cb);
}, }
} };
} }
/** /**
* Package for core.gbapp. * Package for core.gbapp.
*/ */
@ -85,71 +85,74 @@ export class GBBasicPackage implements IGBPackage {
public sysPackages: IGBPackage[]; public sysPackages: IGBPackage[];
public CurrentEngineName = 'guaribas-1.0.0'; public CurrentEngineName = 'guaribas-1.0.0';
public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise<void> { public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise<void> {
core.sequelize.addModels([GuaribasSchedule]); core.sequelize.addModels([GuaribasSchedule]);
}
const dk = new DialogKeywords(); public async getDialogs(min: GBMinInstance) {
const wa = new WebAutomationServices(); GBLog.verbose(`getDialogs called.`);
const sys = new SystemKeywords(); }
const dbg = new DebuggerService(); public async unloadPackage(core: IGBCoreService): Promise<void> {
const img = new ImageProcessingServices(); GBLog.verbose(`unloadPackage 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.`);
}
public async loadBot(min: GBMinInstance): Promise<void> {
const botId = min.botId;
// remote id is required for assigning separate HTTP requests to a single session const opts = {
function getRemoteId(ctx: Koa.Context) { pingSendTimeout: null,
return "1" // share a single session for now, real impl could use cookies or some other meaning for HTTP sessions keepAliveTimeout: null,
}
GBServer.globals.server.dk = createRpcServer(dk, createKoaHttpServer(5555, getRemoteId),{
listeners: { listeners: {
unsubscribed(subscriptions: number): void {}, unsubscribed(subscriptions: number): void {},
subscribed(subscriptions: number): void {}, subscribed(subscriptions: number): void {},
disconnected(remoteId: string, connections: number): void { disconnected(remoteId: string, connections: number): void {
console.log(`Client ${remoteId} disconnected`) GBLogEx.info(min, `[GBAPI]: New client ${remoteId} disconnected`);
}, },
connected(remoteId: string, connections: number): void { connected(remoteId: string, connections: number): void {
console.log(`New client ${remoteId} connected`) GBLogEx.info(min, `[GBAPI]: New client ${remoteId} connected`);
}, },
messageIn(...params): void { messageIn(...params): void {
console.log("IN ", params) GBLogEx.info(min, '[GBAPI]: IN ' + params);
}, },
messageOut(...params): void { messageOut(...params): void {
console.log("OUT ", params) GBLogEx.info(min, '[GBAPI]: OUT ' + params);
}, }
}, }
pingSendTimeout: null, };
keepAliveTimeout: null,
})
console.log("RPC Server started at ws://localhost:5555")
// GBServer.globals.wa = createRpcServer(wa, createWebsocketServer({port: 1112})); function getRemoteId(ctx: Koa.Context) {
// GBServer.globals.sys = createRpcServer(sys, createWebsocketServer({port: 1113})); return '1'; // share a single session for now, real impl could use cookies or some other meaning for HTTP sessions
// GBServer.globals.dbg = createRpcServer(dbg, createWebsocketServer({port: 1114})); }
// GBServer.globals.img = createRpcServer(img, createWebsocketServer({port: 1115})); let instances: IGBInstance[];
} instances = await min.core.loadInstances();
let proxies = {};
await CollectionUtil.asyncForEach(instances, async instance => {
const proxy = {
dk: new DialogKeywords(),
wa: new WebAutomationServices(),
sys: new SystemKeywords(),
dbg: new DebuggerService(),
img: new ImageProcessingServices()
};
proxies[instance.botId] = proxy;
});
public async getDialogs (min: GBMinInstance) { GBServer.globals.server.dk = createRpcServer(
GBLog.verbose(`getDialogs called.`); proxies,
} createKoaHttpServer(GBVMService.API_PORT, getRemoteId, { prefix: `api/v3` }),
public async unloadPackage (core: IGBCoreService): Promise<void> { opts
GBLog.verbose(`unloadPackage called.`); );
}
public async unloadBot (min: GBMinInstance): Promise<void> { GBLogEx.info(min, '[GBAPI] RPC HTTP Server started at http://localhost:' + GBVMService.API_PORT);
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.`);
}
public async loadBot (min: GBMinInstance): Promise<void> {
const botId = min.botId;
GBServer.globals.debuggers[botId] = {}; GBServer.globals.debuggers[botId] = {};
GBServer.globals.debuggers[botId].state = 0; GBServer.globals.debuggers[botId].state = 0;
GBServer.globals.debuggers[botId].breaks = []; GBServer.globals.debuggers[botId].breaks = [];
@ -158,6 +161,5 @@ function getRemoteId(ctx: Koa.Context) {
GBServer.globals.debuggers[botId].client = null; GBServer.globals.debuggers[botId].client = null;
GBServer.globals.debuggers[botId].conversationsMap = {}; GBServer.globals.debuggers[botId].conversationsMap = {};
GBServer.globals.debuggers[botId].watermarkMap = {}; GBServer.globals.debuggers[botId].watermarkMap = {};
} }
} }

View file

@ -695,7 +695,7 @@ export class DialogKeywords {
* @example HEAR name * @example HEAR name
* *
*/ */
public async getHear({ pid, kind, arg }) { public async hear({ pid, kind, arg }) {
let { min, user, params } = await DialogKeywords.getProcessInfo(pid); let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
// Handles first arg as an array of args. // Handles first arg as an array of args.
@ -828,7 +828,7 @@ export class DialogKeywords {
if (result === null) { if (result === null) {
await this.talk({ pid, text: `Escolha por favor um dos itens sugeridos.` }); await this.talk({ pid, text: `Escolha por favor um dos itens sugeridos.` });
return await this.getHear({ pid, kind, arg }); return await this.hear({ pid, kind, arg });
} }
} else if (kind === 'file') { } else if (kind === 'file') {
@ -851,7 +851,7 @@ export class DialogKeywords {
if (value === null) { if (value === null) {
await this.talk({ pid, text: 'Por favor, digite um e-mail válido.' }); await this.talk({ pid, text: 'Por favor, digite um e-mail válido.' });
return await this.getHear({ pid, kind, arg }); return await this.hear({ pid, kind, arg });
} }
result = value; result = value;
@ -864,7 +864,7 @@ export class DialogKeywords {
if (value === null || value.length != 1) { if (value === null || value.length != 1) {
await this.talk({ pid, text: 'Por favor, digite um nome válido.' }); await this.talk({ pid, text: 'Por favor, digite um nome válido.' });
return await this.getHear({ pid, kind, arg }); return await this.hear({ pid, kind, arg });
} }
result = value; result = value;
@ -877,7 +877,7 @@ export class DialogKeywords {
if (value === null || value.length != 1) { if (value === null || value.length != 1) {
await this.talk({ pid, text: 'Por favor, digite um número válido.' }); await this.talk({ pid, text: 'Por favor, digite um número válido.' });
return await this.getHear({ pid, kind, arg }); return await this.hear({ pid, kind, arg });
} }
result = value; result = value;
@ -892,7 +892,7 @@ export class DialogKeywords {
if (value === null || value.length != 1) { if (value === null || value.length != 1) {
await this.talk({ pid, text: 'Por favor, digite uma data no formato 12/12/2020.' }); await this.talk({ pid, text: 'Por favor, digite uma data no formato 12/12/2020.' });
return await this.getHear({ pid, kind, arg }); return await this.hear({ pid, kind, arg });
} }
result = value; result = value;
@ -905,7 +905,7 @@ export class DialogKeywords {
if (value === null || value.length != 1) { if (value === null || value.length != 1) {
await this.talk({ pid, text: 'Por favor, digite um horário no formato hh:ss.' }); await this.talk({ pid, text: 'Por favor, digite um horário no formato hh:ss.' });
return await this.getHear({ pid, kind, arg }); return await this.hear({ pid, kind, arg });
} }
result = value; result = value;
@ -924,7 +924,7 @@ export class DialogKeywords {
if (value === null || value.length != 1) { if (value === null || value.length != 1) {
await this.talk({ pid, text: 'Por favor, digite um valor monetário.' }); await this.talk({ pid, text: 'Por favor, digite um valor monetário.' });
return await this.getHear({ pid, kind, arg }); return await this.hear({ pid, kind, arg });
} }
result = value; result = value;
@ -937,18 +937,18 @@ export class DialogKeywords {
} catch (error) { } catch (error) {
await this.talk({ pid, text: Messages[locale].validation_enter_valid_mobile }); await this.talk({ pid, text: Messages[locale].validation_enter_valid_mobile });
return await this.getHear({ pid, kind, arg }); return await this.hear({ pid, kind, arg });
} }
if (!phoneUtil.isPossibleNumber(phoneNumber)) { if (!phoneUtil.isPossibleNumber(phoneNumber)) {
await this.talk({ pid, text: 'Por favor, digite um número de telefone válido.' }); await this.talk({ pid, text: 'Por favor, digite um número de telefone válido.' });
return await this.getHear({ pid, kind, arg }); return await this.hear({ pid, kind, arg });
} }
result = phoneNumber; result = phoneNumber;
} else if (kind === 'qr-scanner'){ } else if (kind === 'qr-scanner'){
//https://github.com/GeneralBots/BotServer/issues/171 //https://github.com/GeneralBots/BotServer/issues/171
GBLog.info(`BASIC (${min.botId}): Upload done for ${answer.filename}.`); GBLog.info(`BASIC (${min.botId}): Upload done for ${answer.filename}.`);
const handle = WebAutomationServices.cyrb53(this.min.botId + answer.filename); const handle = WebAutomationServices.cyrb53(min.botId + answer.filename);
GBServer.globals.files[handle] = answer; GBServer.globals.files[handle] = answer;
QrScanner.scanImage(GBServer.globals.files[handle]).then(result => console.log(result)).catch(error => console.log(error || 'no QR code found.')); QrScanner.scanImage(GBServer.globals.files[handle]).then(result => console.log(result)).catch(error => console.log(error || 'no QR code found.'));
@ -968,7 +968,7 @@ export class DialogKeywords {
if (value === null || value.length != 1) { if (value === null || value.length != 1) {
await this.talk({ pid, text: 'Por favor, digite um CEP válido.' }); await this.talk({ pid, text: 'Por favor, digite um CEP válido.' });
return await this.getHear({ pid, kind, arg }); return await this.hear({ pid, kind, arg });
} }
result = value[0]; result = value[0];
@ -983,7 +983,7 @@ export class DialogKeywords {
if (result === null) { if (result === null) {
await this.talk({ pid, text: `Escolha por favor um dos itens sugeridos.` }); await this.talk({ pid, text: `Escolha por favor um dos itens sugeridos.` });
return await this.getHear({ pid, kind, arg }); return await this.hear({ pid, kind, arg });
} }
} else if (kind === 'language') { } else if (kind === 'language') {
result = null; result = null;
@ -1015,7 +1015,7 @@ export class DialogKeywords {
if (result === null) { if (result === null) {
await this.talk({ pid, text: `Escolha por favor um dos itens sugeridos.` }); await this.talk({ pid, text: `Escolha por favor um dos itens sugeridos.` });
return await this.getHear({ pid, kind, arg }); return await this.hear({ pid, kind, arg });
} }
} }
return result; return result;
@ -1077,7 +1077,7 @@ export class DialogKeywords {
const { min, user } = await DialogKeywords.getProcessInfo(pid); const { min, user } = await DialogKeywords.getProcessInfo(pid);
if (user) { if (user) {
// TODO: const translate = this.user ? this.user.basicOptions.translatorOn : false; // TODO: const translate = user ? user.basicOptions.translatorOn : false;
await min.conversationalService['sendOnConversation'](min, user, text); await min.conversationalService['sendOnConversation'](min, user, text);
} }

View file

@ -63,6 +63,7 @@ import { SystemKeywords } from './SystemKeywords.js';
*/ */
export class GBVMService extends GBService { export class GBVMService extends GBService {
private static DEBUGGER_PORT = 9222; private static DEBUGGER_PORT = 9222;
public static API_PORT = 1111;
public async loadDialogPackage(folder: string, min: GBMinInstance, core: IGBCoreService, deployer: GBDeployer) { public async loadDialogPackage(folder: string, min: GBMinInstance, core: IGBCoreService, deployer: GBDeployer) {
const files = await walkPromise(folder); const files = await walkPromise(folder);
@ -125,7 +126,8 @@ export class GBVMService extends GBService {
"encoding": "0.1.13", "encoding": "0.1.13",
"isomorphic-fetch": "3.0.0", "isomorphic-fetch": "3.0.0",
"punycode": "2.1.1", "punycode": "2.1.1",
"typescript-rest-rpc": "1.0.10", "@push-rpc/core": "1.1.5",
"@push-rpc/http": "1.1.5",
"vm2": "3.9.11" "vm2": "3.9.11"
} }
}`; }`;
@ -199,17 +201,26 @@ export class GBVMService extends GBService {
code = ` code = `
return (async () => { return (async () => {
// Imports npm packages for this .gbdialog conversational application.
require('isomorphic-fetch'); require('isomorphic-fetch');
const rest = require('typescript-rest-rpc/lib/client'); const createRpcClient = require("@push-rpc/core").createRpcClient;
const createHttpClient = require("@push-rpc/http").createHttpClient;
// Interprocess communication from local HTTP to the BotServer. // Setups interprocess communication from .gbdialog run-time to the BotServer API.
const dk = rest.createClient('http://localhost:1111/api/v2/${min.botId}/dialog'); let url;
const sys = rest.createClient('http://localhost:1111/api/v2/${min.botId}/system'); url = 'http://localhost:${GBVMService.API_PORT}/api/v3/${min.botId}/dk';
const wa = rest.createClient('http://localhost:1111/api/v2/${min.botId}/webautomation'); const dk = (await createRpcClient(0, async () => createHttpClient(url))).remote;
const img = rest.createClient('http://localhost:1111/api/v2/${min.botId}/imagprocessing'); url = 'http://localhost:${GBVMService.API_PORT}/api/v3/${min.botId}/sys';
const sys = (await createRpcClient(0, async () => createHttpClient(url))).remote;
// Local variables. url = 'http://localhost:${GBVMService.API_PORT}/api/v3/${min.botId}/wa';
const wa = (await createRpcClient(0, async () => createHttpClient(url))).remote;
url = 'http://localhost:${GBVMService.API_PORT}/api/v3/${min.botId}/img';
const img = (await createRpcClient(0, async () => createHttpClient(url))).remote;
// Unmarshalls Local variables from server VM.
let pid = this.pid; let pid = this.pid;
let id = this.id; let id = this.id;
@ -228,14 +239,12 @@ export class GBVMService extends GBService {
global[i] = this.variables[i]; global[i] = this.variables[i];
} }
debugger; // Defines local utility BASIC functions.
// Local functions.
const ubound = (array) => {return array.length}; const ubound = (array) => {return array.length};
const isarray = (array) => {return Array.isArray(array) }; const isarray = (array) => {return Array.isArray(array) };
// Remote functions. // Proxies remote functions as BASIC functions.
const weekday = (v) => { return (async () => { return await dk.getWeekFromDate({v}) })(); }; const weekday = (v) => { return (async () => { return await dk.getWeekFromDate({v}) })(); };
const hour = (v) => { return (async () => { return await dk.getHourFromDate({v}) })(); }; const hour = (v) => { return (async () => { return await dk.getHourFromDate({v}) })(); };
@ -423,7 +432,7 @@ export class GBVMService extends GBService {
min: 0, min: 0,
max: 0, max: 0,
debug: debug, debug: debug,
debuggerPort: GBVMService.DEBUGGER_PORT, debuggerport: GBVMService.DEBUGGER_PORT,
botId: botId, botId: botId,
cpu: 100, cpu: 100,
memory: 50000, memory: 50000,

View file

@ -173,112 +173,112 @@ export class KeywordsExpressions {
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as (\w+( \w+)*.xlsx)/gim, /^\s*hear (\w+) as (\w+( \w+)*.xlsx)/gim,
($0, $1, $2) => { ($0, $1, $2) => {
return `${$1} = await dk.getHear({pid: pid, kind:"sheet", arg: "${$2}"})`; return `${$1} = await dk.hear({pid: pid, kind:"sheet", arg: "${$2}"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as\s*login/gim, /^\s*hear (\w+) as\s*login/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({pid: pid, kind:"login"})`; return `${$1} = await dk.hear({pid: pid, kind:"login"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as\s*email/gim, /^\s*hear (\w+) as\s*email/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({pid: pid, kind:"email"})`; return `${$1} = await dk.hear({pid: pid, kind:"email"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as\s*integer/gim, /^\s*hear (\w+) as\s*integer/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({pid: pid, kind:"integer"})`; return `${$1} = await dk.hear({pid: pid, kind:"integer"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as\s*file/gim, /^\s*hear (\w+) as\s*file/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({pid: pid, kind:"file"})`; return `${$1} = await dk.hear({pid: pid, kind:"file"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as\s*boolean/gim, /^\s*hear (\w+) as\s*boolean/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({pid: pid, kind:"boolean"})`; return `${$1} = await dk.hear({pid: pid, kind:"boolean"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as\s*name/gim, /^\s*hear (\w+) as\s*name/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({pid: pid, kind:"name"})`; return `${$1} = await dk.hear({pid: pid, kind:"name"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as\s*date/gim, /^\s*hear (\w+) as\s*date/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({pid: pid, kind:"date"})`; return `${$1} = await dk.hear({pid: pid, kind:"date"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as\s*hour/gim, /^\s*hear (\w+) as\s*hour/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({pid: pid, kind:"hour"})`; return `${$1} = await dk.hear({pid: pid, kind:"hour"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as\s*phone/gim, /^\s*hear (\w+) as\s*phone/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({pid: pid, kind:"phone"})`; return `${$1} = await dk.hear({pid: pid, kind:"phone"})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as\s*money/gim, /^\s*hear (\w+) as\s*money/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({pid: pid, kind:"money")}`; return `${$1} = await dk.hear({pid: pid, kind:"money")}`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as\s*qrcode/gim, /^\s*hear (\w+) as\s*qrcode/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({pid: pid, kind:"qrcode")}`; return `${$1} = await dk.hear({pid: pid, kind:"qrcode")}`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as\s*language/gim, /^\s*hear (\w+) as\s*language/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({pid: pid, kind:"language")}`; return `${$1} = await dk.hear({pid: pid, kind:"language")}`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as\s*zipcode/gim, /^\s*hear (\w+) as\s*zipcode/gim,
($0, $1) => { ($0, $1) => {
return `${$1} = await dk.getHear({pid: pid, kind:"zipcode")}`; return `${$1} = await dk.hear({pid: pid, kind:"zipcode")}`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*hear (\w+) as\s*(.*)/gim, /^\s*hear (\w+) as\s*(.*)/gim,
($0, $1, $2) => { ($0, $1, $2) => {
return `${$1} = await dk.getHear({pid: pid, kind:"menu", args: [${$2}]})`; return `${$1} = await dk.hear({pid: pid, kind:"menu", args: [${$2}]})`;
} }
]; ];
keywords[i++] = [ keywords[i++] = [
/^\s*(hear)\s*(\w+)/gim, /^\s*(hear)\s*(\w+)/gim,
($0, $1, $2) => { ($0, $1, $2) => {
return `${$2} = await dk.getHear({pid: pid})`; return `${$2} = await dk.hear({pid: pid})`;
} }
]; ];
@ -604,7 +604,7 @@ export class KeywordsExpressions {
if ($3.substr(0, 1) !== '"') { if ($3.substr(0, 1) !== '"') {
$3 = `"${$3}"`; $3 = `"${$3}"`;
} }
return `await dk.getTalk ({pid: pid, text: ${$3}})`; return `await dk.talk ({pid: pid, text: ${$3}})`;
} }
]; ];