该函数用于将已经序列化为JSON格式的消息转换为MessageDispatcher可处理的格式。
MessageDispatcher.fromJSON(json: string): Message
json
: 必填,序列化为JSON格式的消息字符串。Message
:MessageDispatcher可处理的消息对象。const message = {
"id": "message-1",
"type": "text",
"content": "Hello world",
"recipient": "user-123",
"sender": "bot-456"
}
const jsonMessage = JSON.stringify(message);
const convertedMessage = MessageDispatcher.fromJSON(jsonMessage);
// convertedMessage: { id: 'message-1', type: 'text', content: 'Hello world', recipient: 'user-123', sender: 'bot-456' }