-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from nathsouzadev/add-social-bank
[feat]add reply buttons
- Loading branch information
Showing
13 changed files
with
305 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,56 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { SocialService } from '../social/services/social.service'; | ||
import { BankMessageModel } from './model/message.model'; | ||
import { CONTENT_BODY } from './constants/content'; | ||
|
||
@Injectable() | ||
export class BankService { | ||
constructor(private readonly socialService: SocialService) {} | ||
|
||
handle = async (data: BankMessageModel) => | ||
this.socialService.replyToWhatsapp({ | ||
handle = async (data: BankMessageModel) => { | ||
if (Object.keys(data.contentReply).includes('button_reply')) { | ||
const content = (() => { | ||
switch (data.contentReply['button_reply'].id) { | ||
case 'balance': | ||
return { | ||
message: `Seu saldo é de R$ 1000,00`, | ||
content: CONTENT_BODY.BALANCE, | ||
}; | ||
case 'purchase': { | ||
return { | ||
message: 'Escolha um item que deseja comprar', | ||
content: CONTENT_BODY.PURCHASE, | ||
}; | ||
} | ||
case 'completed': { | ||
return { | ||
message: 'Compra realizada com sucesso', | ||
content: CONTENT_BODY.PURCHASE_COMPLETED, | ||
}; | ||
} | ||
case 'refused': { | ||
return { | ||
message: 'Compra recusada', | ||
content: CONTENT_BODY.PURCHASE_REFUSED, | ||
}; | ||
} | ||
} | ||
})(); | ||
|
||
return this.socialService.replyToWhatsapp({ | ||
...data, | ||
service: 'bank', | ||
...content, | ||
}); | ||
} | ||
|
||
return this.socialService.replyToWhatsapp({ | ||
...data, | ||
message: '🤗 Bem vinda ao Social Bank!', | ||
service: 'bank', | ||
content: { | ||
type: 'interactive', | ||
recipient_type: 'individual', | ||
interactive: { | ||
type: 'button', | ||
body: { | ||
text: '🤗 Bem vinda ao Social Bank!', | ||
}, | ||
footer: { | ||
text: 'Social Bank é uma demo. Desenvolvido por @nathsouzadev', | ||
}, | ||
action: { | ||
buttons: [ | ||
{ | ||
type: 'reply', | ||
reply: { | ||
title: 'Ver saldo', | ||
id: 'balance', | ||
}, | ||
}, | ||
{ | ||
type: 'reply', | ||
reply: { | ||
title: 'Ver extrato', | ||
id: 'extract', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
content: CONTENT_BODY.WELLCOME, | ||
}); | ||
}; | ||
|
||
balance = () => 1000; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { ButtonData } from 'src/social/model/whats-message.model'; | ||
|
||
const content = (data: { | ||
type: string; | ||
text: string; | ||
buttons?: ButtonData[]; | ||
}) => { | ||
const { type, text, buttons } = data; | ||
|
||
return { | ||
type, | ||
recipient_type: 'individual', | ||
interactive: { | ||
type: 'button', | ||
body: { | ||
text: `${text} \nEscolha uma opção abaixo:`, | ||
}, | ||
footer: { | ||
text: 'Social Bank é uma demo. Desenvolvido por @nathsouzadev', | ||
}, | ||
action: { | ||
buttons: buttons ?? [ | ||
{ | ||
type: 'reply', | ||
reply: { | ||
title: 'Ver saldo', | ||
id: 'balance', | ||
}, | ||
}, | ||
{ | ||
type: 'reply', | ||
reply: { | ||
title: 'Fazer uma compra', | ||
id: 'purchase', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
}; | ||
|
||
export const CONTENT_BODY = { | ||
WELLCOME: content({ | ||
type: 'interactive', | ||
text: '🤗 Bem vinda ao Social Bank!', | ||
}), | ||
BALANCE: content({ | ||
type: 'interactive', | ||
text: '💰💵 Seu saldo é de R$ 1000,00', | ||
}), | ||
PURCHASE: content({ | ||
type: 'interactive', | ||
text: '🛒🛍️ O que deseja comprar?', | ||
buttons: [ | ||
{ | ||
type: 'reply', | ||
reply: { | ||
title: '💻 PC R$ 2000.00', | ||
id: 'refused', | ||
}, | ||
}, | ||
{ | ||
type: 'reply', | ||
reply: { | ||
title: '🖥️ Monitor R$ 500.00', | ||
id: 'completed', | ||
}, | ||
}, | ||
{ | ||
type: 'reply', | ||
reply: { | ||
title: '🖲️ Mouse R$ 100.00', | ||
id: 'completed', | ||
}, | ||
}, | ||
], | ||
}), | ||
PURCHASE_COMPLETED: content({ | ||
type: 'interactive', | ||
text: '🎉🎊 Compra realizada com sucesso!', | ||
}), | ||
PURCHASE_REFUSED: content({ | ||
type: 'interactive', | ||
text: '❌🛒 Compra recusada!', | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
interface TextContent { | ||
body: string; | ||
} | ||
|
||
interface QuickReplyContent { | ||
type: string; | ||
button_reply: { | ||
title: string; | ||
id: string; | ||
}; | ||
} | ||
|
||
export interface BankMessageModel { | ||
from: string; | ||
phoneNumberId: string; | ||
} | ||
from: string; | ||
phoneNumberId: string; | ||
contentReply: TextContent | QuickReplyContent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface IBank { | ||
url: string; | ||
} |
Oops, something went wrong.