我正在使用Twilio API(在angular中使用)聊天应用。消息正在正确发送,但在某些消息中,messages.from(email)
在显示NULL 。
TypeScript代码
//View all messages
// name = localStorage.getItem('name');
allMessages=[];
totalMessages: number;
viewMessage() {
// console.log(this.name + "viewName");
this.chatBox.viewMessages().subscribe(res => {
this.allMessages = res.messages ;
//adding user email address to messages
this.allMessages.forEach(element => {
element.body+=('('+element.from+')')
});
console.log(this.allMessages)
},
err => {
console.log(err);
})
}
以下是我的服务代码
sendMessage(messages):Observable<any>{
return
this.http.post("https://chat.twilio.com/v2/Services/"
+ this.serviceId + "/Channels/" + this.myChannelId + "/Messages",
"ChannelSid=" + this.myChannelId + "&ServiceSid=" + this.serviceId +
"&Body=" + messages + "&From=" + this.identity,this.httpOpt);
}
这是我的html代码
<section class="timeline">
<ul >
<li *ngFor="let message of allMessages">
<div>
{{message.body}}
</div>
</li>
<!-- more list items here -->
</ul>
</section>