Skip to content

Commit

Permalink
fix(whatsapp.gblib): Adding Google to WhatsApp.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Jun 16, 2021
1 parent cdd1a99 commit dc9286f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
1 change: 0 additions & 1 deletion boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var pjson = require('./package.json');

// Displays version of Node JS being used at runtime and others attributes.


console.log(`[GB Runtime] BotServer = v${pjson.version}`);
console.log(`[GB Runtime] BotLib = v${pjson.dependencies.botlib}`);
console.log(`[GB Runtime] BotBuilder (MS) = v${pjson.dependencies.botbuilder}`);
Expand Down
26 changes: 16 additions & 10 deletions packages/core.gbapp/services/GBConversationalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ export class GBConversationalService {
var filetype = href.split('.').pop();
if (videos.indexOf(filetype) > -1) {
var out = '<video autoplay loop alt="' + text + '">'
+ ' <source src="' + href + '" type="video/' + filetype + '">'
+ '</video>'
+ ' <source src="' + href + '" type="video/' + filetype + '">'
+ '</video>'
return out;
} else {
return renderer.oldImage(href, title, text);
Expand All @@ -466,7 +466,7 @@ export class GBConversationalService {
text = text.replace('! [', '![').replace('] (', '](');

text = text.replace(`[[embed url=`, process.env.BOT_URL + '/').replace(']]', ''); // TODO: Improve it.
text = text.replace(`](kb`, "]("+ process.env.BOT_URL + '/kb'); // TODO: Improve it.
text = text.replace(`](kb`, "](" + process.env.BOT_URL + '/kb'); // TODO: Improve it.

// According to the channel, formats the output optimized to it.

Expand Down Expand Up @@ -951,14 +951,20 @@ export class GBConversationalService {
* Sends a message in a user with an already started conversation (got ConversationReference set)
*/
public async sendOnConversation(min: GBMinInstance, user: GuaribasUser, message: string) {
const ref = JSON.parse(user.conversationReference);
MicrosoftAppCredentials.trustServiceUrl(ref.serviceUrl);
await min.bot['createConversation'](ref, async (t1) => {
const ref2 = TurnContext.getConversationReference(t1.activity);
await min.bot.continueConversation(ref2, async (t2) => {
await t2.sendActivity(message);

if (user.conversationReference.startsWith('spaces')) {
await min['googleDirectLine'].sendToDevice(user.userSystemId, null, user.conversationReference, message);
}
else {
const ref = JSON.parse(user.conversationReference);
MicrosoftAppCredentials.trustServiceUrl(ref.serviceUrl);
await min.bot['createConversation'](ref, async (t1) => {
const ref2 = TurnContext.getConversationReference(t1.activity);
await min.bot.continueConversation(ref2, async (t2) => {
await t2.sendActivity(message);
});
});
});
}
}

public static kmpSearch(pattern, text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class FeedbackDialog extends IGBDialog {
user.systemUser = await sec.getUserFromAgentSystemId(agentSystemId);
await min.userProfile.set(step.context, user);

if (agentSystemId.charAt(2) === ":") { // Agent is from Teams.
if (agentSystemId.charAt(2) === ":" || agentSystemId.indexOf("@") > -1) { // Agent is from Teams or Google Chat.
const agent = await sec.getUserFromSystemId(agentSystemId);
await min.conversationalService['sendOnConversation'](min, agent,
Messages[locale].notify_agent(step.context.activity.from.name));
Expand Down
8 changes: 3 additions & 5 deletions packages/whatsapp.gblib/services/WhatsappDirectLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export class WhatsappDirectLine extends GBService {
} else {
GBLog.info(`USER (${id}) TO AGENT ${agent.userSystemId}: ${text}`);

if (user.agentSystemId.charAt(2) === ":") { // Agent is from Teams.
if (user.agentSystemId.charAt(2) === ":" || agent.userSystemId.indexOf("@") > -1) { // Agent is from Teams or Google Chat.
await this.min.conversationalService['sendOnConversation'](this.min, agent, text);
}
else {
Expand Down Expand Up @@ -487,10 +487,8 @@ export class WhatsappDirectLine extends GBService {
}

public async sendToDeviceEx(to, text, locale) {
const minBoot = GBServer.globals.minBoot as any;

text = await minBoot.conversationalService.translate(
minBoot,
text = await this.min.conversationalService.translate(
this.min,
text,
locale
);
Expand Down

0 comments on commit dc9286f

Please sign in to comment.