mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-54994] Use local requests instead of HTTP requests in the flow library (#26471)
This commit is contained in:
parent
3efb25667d
commit
e3d86984cd
@ -27,9 +27,11 @@ type Flow struct {
|
|||||||
|
|
||||||
name Name
|
name Name
|
||||||
api *pluginapi.Client
|
api *pluginapi.Client
|
||||||
pluginURL string
|
pluginID string
|
||||||
botUserID string
|
botUserID string
|
||||||
|
|
||||||
|
siteURL string
|
||||||
|
|
||||||
steps map[Name]Step
|
steps map[Name]Step
|
||||||
index []Name
|
index []Name
|
||||||
done func(userID string, state State) error
|
done func(userID string, state State) error
|
||||||
@ -40,14 +42,28 @@ type Flow struct {
|
|||||||
// NewFlow creates a new flow using direct messages with the user.
|
// NewFlow creates a new flow using direct messages with the user.
|
||||||
//
|
//
|
||||||
// name must be a unique identifier for the flow within the plugin.
|
// name must be a unique identifier for the flow within the plugin.
|
||||||
func NewFlow(name Name, api *pluginapi.Client, pluginURL, botUserID string) *Flow {
|
func NewFlow(name Name, api *pluginapi.Client, pluginID, botUserID string) (*Flow, error) {
|
||||||
|
if api == nil {
|
||||||
|
return nil, errors.New("API client must not be nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
config := api.Configuration.GetConfig()
|
||||||
|
if config == nil {
|
||||||
|
return nil, errors.New("failed to fetch configuration")
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.ServiceSettings.SiteURL == nil {
|
||||||
|
return nil, errors.New("please configure the Mattermost Server's SiteURL, then restart the plugin.")
|
||||||
|
}
|
||||||
|
|
||||||
return &Flow{
|
return &Flow{
|
||||||
name: name,
|
name: name,
|
||||||
api: api,
|
api: api,
|
||||||
pluginURL: pluginURL,
|
pluginID: pluginID,
|
||||||
botUserID: botUserID,
|
botUserID: botUserID,
|
||||||
|
siteURL: strings.TrimRight(*config.ServiceSettings.SiteURL, "/"),
|
||||||
steps: map[Name]Step{},
|
steps: map[Name]Step{},
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Flow) WithSteps(orderedSteps ...Step) *Flow {
|
func (f *Flow) WithSteps(orderedSteps ...Step) *Flow {
|
||||||
|
@ -162,7 +162,7 @@ func (f *Flow) handle(
|
|||||||
|
|
||||||
dialogRequest := model.OpenDialogRequest{
|
dialogRequest := model.OpenDialogRequest{
|
||||||
TriggerId: triggerID,
|
TriggerId: triggerID,
|
||||||
URL: f.pluginURL + namePath(f.name) + "/dialog",
|
URL: "/plugins/" + f.pluginID + namePath(f.name) + "/dialog",
|
||||||
Dialog: processDialog(b.Dialog, state.AppState),
|
Dialog: processDialog(b.Dialog, state.AppState),
|
||||||
}
|
}
|
||||||
dialogRequest.Dialog.State = fmt.Sprintf("%v,%v", fromName, selectedButton)
|
dialogRequest.Dialog.State = fmt.Sprintf("%v,%v", fromName, selectedButton)
|
||||||
@ -205,6 +205,6 @@ func (f *Flow) processButtonPostActions(post *model.Post) {
|
|||||||
if a.Integration == nil {
|
if a.Integration == nil {
|
||||||
a.Integration = &model.PostActionIntegration{}
|
a.Integration = &model.PostActionIntegration{}
|
||||||
}
|
}
|
||||||
a.Integration.URL = f.pluginURL + namePath(f.name) + "/button"
|
a.Integration.URL = "/plugins/" + f.pluginID + namePath(f.name) + "/button"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ func (f *Flow) processAttachment(attachment *model.SlackAttachment) *model.Slack
|
|||||||
if u.Host != "" && (u.Scheme == "http" || u.Scheme == "https") {
|
if u.Host != "" && (u.Scheme == "http" || u.Scheme == "https") {
|
||||||
a.ImageURL = attachment.ImageURL
|
a.ImageURL = attachment.ImageURL
|
||||||
} else {
|
} else {
|
||||||
a.ImageURL = f.pluginURL + "/" + strings.TrimPrefix(attachment.ImageURL, "/")
|
a.ImageURL = fmt.Sprintf("%s/plugins/%s/%s", f.siteURL, f.pluginID, strings.TrimPrefix(attachment.ImageURL, "/"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user