fix(core.gbapp): Auto start fixed for wa, teams and web.

This commit is contained in:
Rodrigo Rodriguez 2021-06-04 11:15:23 -03:00
parent 5fa88f0e7e
commit 5021e7fcf1
4 changed files with 54 additions and 27 deletions

View file

@ -715,7 +715,7 @@ export class GBVMService extends GBService {
delete min.cbMap[id];
try {
const opts = await promise(step, result);
if (Object.keys(min.cbMap).length) {
if (Object.keys(min.cbMap).length > 0) {
return await step.replaceDialog('/hear', opts);
}
} catch (error) {

View file

@ -225,7 +225,6 @@ export class GBConversationalService {
}
}
public async sendFile(
min: GBMinInstance,
step: GBDialogStep,

View file

@ -313,8 +313,8 @@ export class GBMinService {
user.hearOnDialog :
activeMin.core.getParam(activeMin.instance, 'Start Dialog', null);
GBLog.info(`Auto start (1) dialog is now being called: ${startDialog} for ${activeMin.instance.instanceId}...`);
if (startDialog) {
GBLog.info(`Calling /call to Auto start ${startDialog} for ${activeMin.instance.instanceId}...`);
req.body.messages[0].body = `/call ${startDialog}`;
// Resets HEAR ON DIALOG value to none and passes
@ -342,9 +342,10 @@ export class GBMinService {
await sec.updateUserInstance(id, instance.instanceId);
await (activeMin as any).whatsAppDirectLine.resetConversationId(id);
const startDialog = activeMin.core.getParam(activeMin.instance, 'Start Dialog', null);
GBLog.info(`Auto start (2) dialog is now being called: ${startDialog} for ${activeMin.instance.botId}...`);
if (startDialog) {
GBLog.info(`Calling /call for Auto start : ${startDialog} for ${activeMin.instance.botId}...`);
req.body.messages[0].body = `/call ${startDialog}`;
await (activeMin as any).whatsAppDirectLine.received(req, res);
} else {
@ -717,6 +718,19 @@ export class GBMinService {
});
}
// TODO: Unify in util.
public userMobile(step) {
if (isNaN(step.context.activity['mobile'])) {
if (step.context.activity.from && !isNaN(step.context.activity.from.id)) {
return step.context.activity.from.id;
}
return null;
} else {
return step.context.activity['mobile'];
}
}
/**
* BOT Framework web service hook method.
*/
@ -812,6 +826,15 @@ export class GBMinService {
TurnContext.getConversationReference(context.activity)
);
await sec.updateConversationReferenceById(user.systemUser.userId, conversationReference);
if (!user.welcomed) {
const startDialog = min.core.getParam(min.instance, 'Start Dialog', null);
if (startDialog && !user.welcomed) {
user.welcomed = true;
GBLog.info(`Auto start (teams) dialog is now being called: ${startDialog} for ${min.instance.botId}...`);
await GBVMService.callVM(startDialog.toLowerCase(), min, step, this.deployer);
}
}
}
GBLog.info(`User>: text:${context.activity.text} (type: ${context.activity.type}, name: ${context.activity.name}, channelId: ${context.activity.channelId}, value: ${context.activity.value})`);
@ -820,8 +843,7 @@ export class GBMinService {
// Skips if the bot is talking.
if (context.activity.type === 'conversationUpdate' &&
context.activity.membersAdded.length > 0&&
context.activity.membersAdded[0].id.indexOf(min.botId) == -1) {
context.activity.membersAdded.length > 0) {
// Check if a bot or a human participant is being added to the conversation.
@ -839,22 +861,15 @@ export class GBMinService {
const startDialog = min.core.getParam(min.instance, 'Start Dialog', null);
if (!startDialog && user.welcomed) {
// Otherwise, calls / (root) to default welcome users.
await step.beginDialog('/');
}
else {
} else {
GBLog.info(`Member added to conversation: ${member.name}`);
const startDialog = min.core.getParam(min.instance, 'Start Dialog', null);
if (startDialog && !user.welcomed) {
user.welcomed = true;
GBLog.info(`Auto start (3) dialog is now being called: ${startDialog} for ${min.instance.instanceId}...`);
await GBVMService.callVM(startDialog.toLowerCase(), min, step, this.deployer);
}
GBLog.info(`Member added to conversation: ${member.name}`);
}
}
} else if (context.activity.type === 'message') {
@ -867,7 +882,7 @@ export class GBMinService {
// Processes events activies.
await this.processEventActivity(context, step);
await this.processEventActivity(min, user, context, step);
}
// Saves conversation state for later use.
@ -893,7 +908,7 @@ export class GBMinService {
/**
* Called to handle all event sent by .gbui clients.
*/
private async processEventActivity(context, step: GBDialogStep) {
private async processEventActivity(min, user, context, step: GBDialogStep) {
if (context.activity.name === 'whoAmI') {
await step.beginDialog('/whoAmI');
@ -914,6 +929,13 @@ export class GBMinService {
await step.beginDialog('/quality', {
score: context.activity.data
});
} else if (context.activity.name === 'startGB') {
const startDialog = min.core.getParam(min.instance, 'Start Dialog', null);
if (startDialog && !user.welcomed) {
user.welcomed = true;
GBLog.info(`Auto start (web) dialog is now being called: ${startDialog} for ${min.instance.instanceId}...`);
await GBVMService.callVM(startDialog.toLowerCase(), min, step, this.deployer);
}
} else if (context.activity.name === 'updateToken') {
const token = context.activity.data;
await step.beginDialog('/adminUpdateToken', { token: token });

View file

@ -96,15 +96,20 @@ class GBUIApp extends React.Component {
return { id: 'web@gb', name: 'You' };
}
postEvent(name, value) {
window.line.postActivity({
type: 'event',
value: value,
from: this.getUser(),
name: name
});
postEvent(name, item) {
setTimeout(()=>{
window['botConnection'].postActivity({
type: "event",
name: name,
data: item,
locale: "en-us",
textFormat: "plain",
timestamp: new Date().toISOString(),
from: window.user
})
.subscribe(console.log("success"));
},400);
}
postMessage(value) {
window.line.postActivity({
type: 'message',
@ -319,6 +324,7 @@ class GBUIApp extends React.Component {
);
if (this.state.line && this.state.instance) {
this.postEvent('startGB', true);
gbCss = <GBCss instance={this.state.instance} />;
seo = <SEO instance={this.state.instance}/>;