2
我試圖用鬆散的機器人發送帶附件的消息給閒聊。與api的連接是通過WebSocket完成的,直到現在,一切正常,除了發送帶附件的消息之外,所有的東西都可以正常工作。Slack API只拾取文本字段
這裏是代碼片段發送消息:
public final void replyInteractive(WebSocketSession session, Event event, InteractiveMessage reply) {
try {
reply.setText(encode(reply.getText()));
reply.setType(EventType.MESSAGE.name().toLowerCase());
if (reply.getChannel() == null && event.getChannelId() != null) {
reply.setChannel(event.getChannelId());
}
session.sendMessage(new TextMessage(reply.toJSONString()));
if (logger.isDebugEnabled()) { // For debugging purpose only
logger.debug("Reply (Message): {}", reply.toJSONString());
}
} catch (IOException e) {
logger.error("Error sending event: {}. Exception: {}", event.getText(), e.getMessage());
}
}
這是該代碼發送JSON:
{"type":"message","channel":"D4CJ8B337","text":"New book!","attachments":[{"fallback":"Something went wrong","color":"#3AA3E3","title":"Do you want to buy this book?","actions":[{"name":"Buy","value":"Yes","text":"Buy","type":"button"},{"name":"No","value":"No","text":"No","type":"button"}],"attachment_type":"default","callback_id":"Djisda"}]}
但是,正如我所說,只有文本字段,「新書!「,正在接受並在聊天中顯示。當我使用Slack Message Builder測試它時,整個消息似乎是有效的。 我想就是這樣,在此先感謝。