I have successfully set up a chat interface that displays messages on the left side of the screen when sent or received from dialog flow. However, I would like to customize it so that my messages appear on the right side while dialog flow messages remain on the left side, each represented by different colored chat bubbles. I am unsure how to achieve this differentiation and would appreciate some guidance. Below is my HTML code.
<ion-content>
<div style="font-size:10px; text-align:center;">7 minutes ago</div>
<div class="msgbubble" *ngFor="let msg of messages">
<div class="innermsg">
{{ msg }}
</div>
</div>
</ion-content>
<ion-footer>
<ion-toolbar>
<ion-input placeholder="Type here" [(ngModel)]="question" type="text"></ion-input>
<ion-buttons right>
<button ion-button clear icon-only id="sendicon" (click)="ask(question)">
<ion-icon name="send"></ion-icon>
</button>
</ion-buttons>
</ion-toolbar>
</ion-footer>
This is ts code.
ask(question) {
try {
this.messages.push(question);
var headers = new Headers();
headers.append("Accept", 'application/json');
headers.append('Content-Type', 'application/json' );
headers.append('Authorization', 'Bearer ' + this.Access_token)
let options = new RequestOptions({ headers: headers });
let postParams = {
"lang": "en",
"query": question ,
"sessionId": "12345",
"timezone": "America/New_York"
}
try{
this.http.post("https://api.dialogflow.com/v1/query?v=20150910", postParams, options)
.subscribe(data => {
let obj = JSON.parse(data['_body']);
this.answer = obj.result.fulfillment.speech;
//console.log(data['_body']);
console.log(this.answer);
this.messages.push(this.answer);
}, error => {
console.log(error);// Error getting the data
});
}
catch(e){
console.log(e);
}
}
catch(e){
console.log(e);
}
}
I envision the UI resembling a typical chat page or bot where my messages are displayed on the right and incoming messages on the left.