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]; delete min.cbMap[id];
try { try {
const opts = await promise(step, result); 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); return await step.replaceDialog('/hear', opts);
} }
} catch (error) { } catch (error) {

View file

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

View file

@ -313,8 +313,8 @@ export class GBMinService {
user.hearOnDialog : user.hearOnDialog :
activeMin.core.getParam(activeMin.instance, 'Start Dialog', null); 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) { if (startDialog) {
GBLog.info(`Calling /call to Auto start ${startDialog} for ${activeMin.instance.instanceId}...`);
req.body.messages[0].body = `/call ${startDialog}`; req.body.messages[0].body = `/call ${startDialog}`;
// Resets HEAR ON DIALOG value to none and passes // Resets HEAR ON DIALOG value to none and passes
@ -342,9 +342,10 @@ export class GBMinService {
await sec.updateUserInstance(id, instance.instanceId); await sec.updateUserInstance(id, instance.instanceId);
await (activeMin as any).whatsAppDirectLine.resetConversationId(id); await (activeMin as any).whatsAppDirectLine.resetConversationId(id);
const startDialog = activeMin.core.getParam(activeMin.instance, 'Start Dialog', null); 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) { if (startDialog) {
GBLog.info(`Calling /call for Auto start : ${startDialog} for ${activeMin.instance.botId}...`);
req.body.messages[0].body = `/call ${startDialog}`; req.body.messages[0].body = `/call ${startDialog}`;
await (activeMin as any).whatsAppDirectLine.received(req, res); await (activeMin as any).whatsAppDirectLine.received(req, res);
} else { } 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. * BOT Framework web service hook method.
*/ */
@ -812,6 +826,15 @@ export class GBMinService {
TurnContext.getConversationReference(context.activity) TurnContext.getConversationReference(context.activity)
); );
await sec.updateConversationReferenceById(user.systemUser.userId, conversationReference); 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})`); 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. // Skips if the bot is talking.
if (context.activity.type === 'conversationUpdate' && if (context.activity.type === 'conversationUpdate' &&
context.activity.membersAdded.length > 0&& context.activity.membersAdded.length > 0) {
context.activity.membersAdded[0].id.indexOf(min.botId) == -1) {
// Check if a bot or a human participant is being added to the conversation. // Check if a bot or a human participant is being added to the conversation.
@ -844,16 +866,9 @@ export class GBMinService {
await step.beginDialog('/'); await step.beginDialog('/');
} }
else {
} else {
GBLog.info(`Member added to conversation: ${member.name}`); 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);
} }
} }
@ -867,7 +882,7 @@ export class GBMinService {
// Processes events activies. // Processes events activies.
await this.processEventActivity(context, step); await this.processEventActivity(min, user, context, step);
} }
// Saves conversation state for later use. // Saves conversation state for later use.
@ -893,7 +908,7 @@ export class GBMinService {
/** /**
* Called to handle all event sent by .gbui clients. * 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') { if (context.activity.name === 'whoAmI') {
await step.beginDialog('/whoAmI'); await step.beginDialog('/whoAmI');
@ -914,6 +929,13 @@ export class GBMinService {
await step.beginDialog('/quality', { await step.beginDialog('/quality', {
score: context.activity.data 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') { } else if (context.activity.name === 'updateToken') {
const token = context.activity.data; const token = context.activity.data;
await step.beginDialog('/adminUpdateToken', { token: token }); await step.beginDialog('/adminUpdateToken', { token: token });

View file

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