owned this note
owned this note
Published
Linked with GitHub
# Enterprise Chat Application: Development Guide
## Introduction
This document outlines the development plan for an enterprise chat application that facilitates chat between business representatives using a web chat application or Microsoft Teams, and their customers via SMS. The solution integrates SendBird for the chat interface, Bandwidth for SMS and MMS capabilities, AWS Cognito for user authentication and single sign-on, and DynamoDB for message storage. GDPR compliance is paramount.
## Non-Functional Requirements (NFR)
1. **Scalability**: The system should support up to 20,000 users simultaneously.
2. **Security**: All user data and messages must be encrypted both in transit and at rest.
3. **Responsiveness**: The chat UI should be real-time without any perceptible delay.
4. **Compliance**: GDPR compliance to ensure user data protection.
5. **Integration**: Seamless integration with MS Teams and a custom web chat application.
## Functional Requirements (FR)
1. **User Authentication**: Users should authenticate using Single Sign-On through AWS Cognito.
2. **Chat Interface**: Utilize SendBird to facilitate real-time chat on web and MS Teams.
3. **SMS Communication**: Allow for business representatives to send SMS to customers using Bandwidth API.
4. **MMS Communication**: Extend chat functionality for multimedia (image/video) transfers.
5. **Message Logging**: All messages should be saved in the existing DynamoDB instance for record-keeping and potential analytics.
## Architecture
This diagram will depict how various components interact within the system.
```mermaid
graph LR
T[Teams SSO] --> |Federation| A
A[AWS Cognito] -->|Authentication| B[Web Chat Application / MS Teams]
B -->|Initiate Chat| C[SendBird Chat]
C -->|Send/Receive SMS/MMS| D[Bandwidth SMS/MMS API]
D --> E[Customer's Mobile]
subgraph Amazon AWS
C
F[DynamoDB]
G[AWS Elastic Beanstalk]
end
D -->|Log Messages| F
B -->|Deploy| G
style A fill:#f9d,stroke:#333,stroke-width:2px
style B fill:#fdc,stroke:#333,stroke-width:2px
style C fill:#bfd,stroke:#333,stroke-width:2px
style D fill:#edc,stroke:#333,stroke-width:2px
style E fill:#cfd,stroke:#333,stroke-width:2px
style F fill:#adf,stroke:#333,stroke-width:2px
style G fill:#dfe,stroke:#333,stroke-width:2px
```
Here's the breakdown of the diagram:
- **AWS Cognito**: Represents the Single Sign-On system. This is where users will authenticate.
- **Web Chat Application / MS Teams**: This is the frontend where your enterprise users will interact. They will authenticate using AWS Cognito and then get directed here.
- **SendBird Chat**: This is the chat backend handling real-time messaging on the web app and MS Teams.
- **Bandwidth SMS/MMS API**: This is responsible for sending and receiving SMS and MMS messages to/from customers.
- **Customer's Mobile**: Represents the endpoint of the SMS/MMS communication.
- **DynamoDB**: This is where messages are logged and stored.
- **AWS Elastic Beanstalk**: Represents the deployment environment for your web application.
The arrows indicate the flow of information and interaction between the components. For example, once authenticated through AWS Cognito, users can access the chat application. When a message is initiated from the chat application, it goes through SendBird, which then communicates with Bandwidth API to send an SMS or MMS. Similarly, incoming messages will traverse the same path in reverse. All messages are logged in DynamoDB. The entire system, except the customer's mobile, resides within the AWS ecosystem.
## Message Flow
Sequence diagram illustrating the interaction flow between the user, Web Chat / MS Teams interface, SendBird backend, and Bandwidth SMS API, along with API samples:
```mermaid
sequenceDiagram
participant User
participant WebChat
participant SendBird
participant BE
participant Bandwidth
participant DynamoDB as MessageDB
User ->> WebChat: Login
WebChat ->> SendBird: Authenticate using JWT from AWS Cognito
SendBird -->> WebChat: Authentication successful
User ->> WebChat: Enter message "Hello"
WebChat ->> BE: Forward message to be processed
BE ->> DynamoDB: Store message with status "Pending"
BE ->> Bandwidth: POST SMS to +17036089795
note right of Bandwidth: to: +17036089795<br>from: +17866181889<br>text: "Hello"
Bandwidth-->> BE: SMS sent notification
BE ->> DynamoDB: Update message status to "Sent"
BE -->> WebChat: Message sent notification
User ->> WebChat: View sent message status
note over Bandwidth,User: Later, when a reply comes
Bandwidth ->> BE: Incoming SMS from +17036089795
note right of BE: from: +17036089795<br>text: "Hi there!"
BE ->> DynamoDB: Store incoming message
BE -->> WebChat: Display incoming message
User ->> WebChat: View incoming message
```
Here's a breakdown:
1. **User Login and Authentication**:
- The user logs into the WebChat or MS Teams interface.
- WebChat/MS Teams interface communicates with SendBird to authenticate using JWT (JSON Web Token) which was acquired from AWS Cognito.
2. **Sending an SMS**:
- The user sends a message through the WebChat interface.
- This message goes to the SendBird backend which then communicates with Bandwidth's API to send the SMS.
- API sample for sending an SMS is provided in the right note of Bandwidth in the diagram.
3. **Receiving an SMS**:
- When a customer replies to the SMS, Bandwidth's API picks it up.
- The incoming message is sent to the SendBird backend, which then pushes the message to the WebChat interface.
- The user can then view this incoming message in the chat interface.
## Development Schedule
1. **Day 1**:
- ✅Setup the development environment.
- ✅Begin integration of AWS Cognito for user authentication.
- ✅Setup basic chat interface with SendBird.
2. **Day 2**:
- Complete AWS Cognito integration.
- ✅Integrate Bandwidth API for SMS communication.
- ✅Start on MMS functionality.
3. **Day 3**:
- ✅Finish MMS functionality.
- ✅Integration tests for SMS/MMS and SendBird chat.
- ✅Integrate MS Teams app for business representatives.
4. **Day 4**:
- ✅Finalize the UI/UX customizations.
- ✅Conduct thorough testing across all platforms.
- ✅Deploy to Elastic Beanstalk.
- Provide documentation and usage guides.
## Acceptance Criteria
1. Successful user authentication using Single Sign-On.
2. Real-time chat functionality in the web app and MS Teams.
3. Successful sending and receiving of SMS and MMS between business representatives and customers.
4. Messages should be stored in DynamoDB.
5. GDPR compliance verified.
6. Successful deployment to Elastic Beanstalk with no reported errors.
## Modified Webex BandwidthSMSService.java
To integrate with Sendbird, you need to utilize the Sendbird SDK or API for Java. The Sendbird SDK will help you handle incoming and outgoing chat messages. In the context of your existing Bandwidth integration:
1. When an SMS comes in via Bandwidth:
- The system processes the SMS and sends it to the appropriate user on Sendbird.
2. When a user replies on Sendbird:
- The system captures that message and sends it out as an SMS via Bandwidth.
**To achieve this, follow these steps**:
1. **Setup Sendbird SDK**:
- Add the Sendbird SDK to your `pom.xml` or `build.gradle` file (I'll use Maven as an example):
```xml
<dependency>
<groupId>com.sendbird.sdk</groupId>
<artifactId>sendbird-android-sdk</artifactId>
<version>LATEST_VERSION</version>
</dependency>
```
2. **Sendbird Configuration**:
```java
import com.sendbird.android.SendBird;
import com.sendbird.android.SendBirdException;
@Service
public class SendbirdService {
@Value("${sendbird.appId}")
private String sendbirdAppId;
@PostConstruct
public void init() {
SendBird.init(sendbirdAppId, ApplicationContextProvider.getContext());
}
}
```
3. **Handle Incoming SMS and Send to Sendbird**:
Add to your existing `BandwidthSMSService`:
```java
import com.sendbird.android.BaseChannel;
import com.sendbird.android.GroupChannel;
import com.sendbird.android.SendBirdException;
import com.sendbird.android.UserMessage;
...
private void sendToSendbirdChat(String userId, String messageText) {
GroupChannel.getChannel(CHANNEL_URL, new GroupChannel.GroupChannelGetHandler() {
@Override
public void onResult(GroupChannel groupChannel, SendBirdException e) {
if (e != null) {
log.error("Error fetching Sendbird channel: {}", e.getMessage());
return;
}
groupChannel.sendUserMessage(messageText, null, null, new BaseChannel.SendUserMessageHandler() {
@Override
public void onSent(UserMessage userMessage, SendBirdException e) {
if (e != null) {
log.error("Error sending message to Sendbird: {}", e.getMessage());
return;
}
}
});
}
});
}
// Adjust your validateNumberAndSendMessage function to include:
sendToSendbirdChat(numberToMessageAppMap.getEnterprise().getUserId(), bandwidthMessage.getText());
```
4. **Handle Sendbird Reply and Send SMS**:
You'll likely set up a webhook in Sendbird to listen for new messages. When received at your application endpoint, you should process and send as SMS.
```java
@RestController
@RequestMapping("/sendbird")
public class SendbirdController {
@Autowired
private BandwidthSMSService bandwidthSMSService;
@PostMapping("/incoming-message")
public ResponseEntity handleIncomingSendbirdMessage(@RequestBody SendbirdMessageDto messageDto) {
if (messageDto != null) {
bandwidthSMSService.sendSMSViaBandwidth(messageDto.getTo(), messageDto.getFrom(), messageDto.getMessageText(), null, null);
}
return ResponseEntity.ok().build();
}
}
// Where SendbirdMessageDto is a DTO that you define to capture necessary message information from Sendbird's webhook payload.
```
5. **Error Handling and Improvements**:
- Ensure you have proper error handling in place for any Sendbird exceptions.
- Secure your endpoints that interact with Bandwidth and Sendbird.
- Adjust the Sendbird integration as per your exact needs.
Remember to replace placeholders like `CHANNEL_URL` with your actual values. This integration assumes you're using group channels in Sendbird. Adjust based on your Sendbird implementation (open channels, one-to-one, etc.).