fix(dingtalk): parse rich text image messages
This commit is contained in:
@@ -35,3 +35,58 @@ func TestParseDingTalkStreamPayloadPictureJSONString(t *testing.T) {
|
||||
t.Fatalf("got type=%q fileKey=%q", messageType, fileKey)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDingTalkStreamPayloadRichTextWithPictureAndText(t *testing.T) {
|
||||
messageType, content, fileKey := parseDingTalkStreamPayload("richText", map[string]interface{}{
|
||||
"richText": []interface{}{
|
||||
map[string]interface{}{"text": " 请回答图片中的问题 "},
|
||||
map[string]interface{}{"type": "picture", "downloadCode": "rich-stream-code"},
|
||||
},
|
||||
}, "")
|
||||
|
||||
if messageType != im.MessageTypeImage {
|
||||
t.Fatalf("MessageType = %q, want image", messageType)
|
||||
}
|
||||
if content != "请回答图片中的问题" {
|
||||
t.Fatalf("content = %q", content)
|
||||
}
|
||||
if fileKey != "rich-stream-code" {
|
||||
t.Fatalf("fileKey = %q", fileKey)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDingTalkStreamPayloadRichTextJoinsTextParts(t *testing.T) {
|
||||
messageType, content, fileKey := parseDingTalkStreamPayload("richText", map[string]interface{}{
|
||||
"richText": []interface{}{
|
||||
map[string]interface{}{"text": "第一段"},
|
||||
map[string]interface{}{"type": "picture", "downloadCode": "rich-code"},
|
||||
map[string]interface{}{"text": "第二段"},
|
||||
},
|
||||
}, "")
|
||||
if messageType != im.MessageTypeImage || content != "第一段\n第二段" || fileKey != "rich-code" {
|
||||
t.Fatalf("got type=%q content=%q fileKey=%q", messageType, content, fileKey)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDingTalkStreamPayloadRichTextWithoutPictureStaysText(t *testing.T) {
|
||||
messageType, content, fileKey := parseDingTalkStreamPayload("richText", map[string]interface{}{
|
||||
"richText": []interface{}{
|
||||
map[string]interface{}{"text": " 只有文字 "},
|
||||
},
|
||||
}, "")
|
||||
if messageType != im.MessageTypeText || content != "只有文字" || fileKey != "" {
|
||||
t.Fatalf("got type=%q content=%q fileKey=%q", messageType, content, fileKey)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDingTalkStreamPayloadRichTextPictureWithoutDownloadCodeStaysImage(t *testing.T) {
|
||||
messageType, content, fileKey := parseDingTalkStreamPayload("richText", map[string]interface{}{
|
||||
"richText": []interface{}{
|
||||
map[string]interface{}{"text": "识别图片"},
|
||||
map[string]interface{}{"type": "picture"},
|
||||
},
|
||||
}, "")
|
||||
if messageType != im.MessageTypeImage || content != "识别图片" || fileKey != "" {
|
||||
t.Fatalf("got type=%q content=%q fileKey=%q", messageType, content, fileKey)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user