Files
WeKnora/pluginsdk/pluginapi/im.go
wizardchen 3ab8809435 feat(plugin): plugins bring IM platforms
contributes.imChannels is open to third-party plugins. A plugin IM
platform (its qualified ID, e.g. acme.zulip/zulip) joins the channel
editor's list with its instanceSchema as the credential form; secrets are
redacted and merged like the builtin platforms'. Channels connect over
webhooks: WeKnora relays each callback to the plugin, which answers the
platform (challenges, acks) and hands back the user's message; the
channel's agent answers and the plugin sends the reply. Long-connection
platforms are not supported yet.

The IM platform columns widen to 160 characters (versioned 000122) for
qualified IDs. Go and Python SDKs gain IM channels.
2026-09-26 16:29:51 +08:00

41 lines
1.6 KiB
Go

package pluginapi
// IMCallbackPath is where WeKnora relays an IM platform's callback to IM
// channel id; IMSendPath is where it asks the plugin to reply.
func IMCallbackPath(id string) string { return "/v1/im/" + id + "/callback" }
// IMSendPath is the reply endpoint of IM channel id.
func IMSendPath(id string) string { return "/v1/im/" + id + "/send" }
// IMCallbackOutput is what a platform's callback amounts to: the HTTP
// answer the platform expects (a URL verification challenge, an ack) and,
// when it carried one, the user's message for WeKnora to answer.
type IMCallbackOutput struct {
// Response is written back to the platform; nil answers 200 "{}".
Response *WebhookResponse `json:"response,omitempty"`
Message *IMMessage `json:"message,omitempty"`
}
// IMMessage is a user's message in a chat.
type IMMessage struct {
UserID string `json:"userId"`
UserName string `json:"userName,omitempty"`
// ChatID is the conversation (the user for direct chats).
ChatID string `json:"chatId"`
// ChatType is "direct" or "group".
ChatType string `json:"chatType,omitempty"`
Content string `json:"content"`
MessageID string `json:"messageId,omitempty"`
ThreadID string `json:"threadId,omitempty"`
// Extra carries what the plugin needs to reply (a response URL).
Extra map[string]string `json:"extra,omitempty"`
}
// IMSendInput is a reply to a message.
type IMSendInput struct {
// Message is the one being answered, as the callback reported it.
Message IMMessage `json:"message"`
// Content is the answer, Markdown.
Content string `json:"content"`
}