mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-10-26 22:37:00 +00:00
f73434eea7
An article written in another language can now be joined to an existing article as its translation, or pulled back out into its own group. Also caps transcript downloads at 1000 messages and fixes the field widths in the automation rule and action rows.
41 lines
1.5 KiB
Go
41 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"mime"
|
|
"time"
|
|
|
|
cmodels "github.com/abhinavxd/libredesk/internal/conversation/models"
|
|
"github.com/abhinavxd/libredesk/internal/envelope"
|
|
"github.com/abhinavxd/libredesk/internal/stringutil"
|
|
"github.com/zerodha/fastglue"
|
|
)
|
|
|
|
func handleWidgetTranscript(r *fastglue.Request) error {
|
|
app := r.Context.(*App)
|
|
config, err := getWidgetConfig(r)
|
|
if err != nil {
|
|
return sendErrorEnvelope(r, err)
|
|
}
|
|
if !config.Features.Transcript {
|
|
return sendErrorEnvelope(r, envelope.NewError(envelope.PermissionError, app.i18n.T("status.deniedPermission"), nil))
|
|
}
|
|
uuid := r.RequestCtx.UserValue("uuid").(string)
|
|
_, conversation, err := getContactConversation(r, uuid)
|
|
if err != nil {
|
|
return sendErrorEnvelope(r, err)
|
|
}
|
|
private := false
|
|
messages, err := app.conversation.GetAllConversationMessages(uuid, &private, []string{cmodels.MessageIncoming, cmodels.MessageOutgoing}, maxTranscriptDownloadMessages)
|
|
if err != nil {
|
|
return sendErrorEnvelope(r, err)
|
|
}
|
|
filename := fmt.Sprintf("transcript-%s.txt", stringutil.SanitizeFilename(conversation.ReferenceNumber))
|
|
r.RequestCtx.Response.Header.Set("Content-Disposition", mime.FormatMediaType("attachment", map[string]string{"filename": filename}))
|
|
r.RequestCtx.Response.Header.Set("Cache-Control", "private, no-store")
|
|
r.RequestCtx.Response.Header.Set("X-Content-Type-Options", "nosniff")
|
|
r.RequestCtx.SetContentType("text/plain; charset=utf-8")
|
|
r.RequestCtx.SetBody(app.conversation.BuildTranscript(conversation, messages, time.Now()))
|
|
return nil
|
|
}
|