Show untranslated text in attachment when using Slack.
This commit is contained in:
@@ -38,6 +38,7 @@ type Message struct {
|
|||||||
Timestamp time.Time `json:"timestamp"`
|
Timestamp time.Time `json:"timestamp"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Extra map[string][]interface{}
|
Extra map[string][]interface{}
|
||||||
|
TranslationSrcMsg *Message
|
||||||
}
|
}
|
||||||
|
|
||||||
type FileInfo struct {
|
type FileInfo struct {
|
||||||
|
|||||||
@@ -230,6 +230,11 @@ func (b *Bslack) Send(msg config.Message) (string, error) {
|
|||||||
np.Attachments = append(np.Attachments, slack.Attachment{CallbackID: "matterbridge_" + b.uuid})
|
np.Attachments = append(np.Attachments, slack.Attachment{CallbackID: "matterbridge_" + b.uuid})
|
||||||
// add file attachments
|
// add file attachments
|
||||||
np.Attachments = append(np.Attachments, b.createAttach(msg.Extra)...)
|
np.Attachments = append(np.Attachments, b.createAttach(msg.Extra)...)
|
||||||
|
// add translation attachment
|
||||||
|
if msg.TranslationSrcMsg != nil {
|
||||||
|
// If source, then we're doing a translation
|
||||||
|
np.Attachments = append(np.Attachments, b.createTranslationAttach(msg))
|
||||||
|
}
|
||||||
// add slack attachments (from another slack bridge)
|
// add slack attachments (from another slack bridge)
|
||||||
if msg.Extra != nil {
|
if msg.Extra != nil {
|
||||||
for _, attach := range msg.Extra[sSlackAttachment] {
|
for _, attach := range msg.Extra[sSlackAttachment] {
|
||||||
@@ -285,6 +290,30 @@ func (b *Bslack) createAttach(extra map[string][]interface{}) []slack.Attachment
|
|||||||
return attachements
|
return attachements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Bslack) createTranslationAttach(msg config.Message) slack.Attachment {
|
||||||
|
untranslatedTextPreview := msg.TranslationSrcMsg.Text[:100]+"..."
|
||||||
|
ch, err := b.getChannelByName(msg.TranslationSrcMsg.Channel)
|
||||||
|
time := strings.Split(msg.TranslationSrcMsg.ID, " ")[1]
|
||||||
|
params := slack.PermalinkParameters{
|
||||||
|
Channel: ch.ID,
|
||||||
|
Ts: time,
|
||||||
|
}
|
||||||
|
b.Log.Debugf("Generating permalink...")
|
||||||
|
permalink, err := b.sc.GetPermalink(¶ms)
|
||||||
|
if err != nil {
|
||||||
|
b.Log.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
attach := slack.Attachment{
|
||||||
|
Fallback: trimmed,
|
||||||
|
Text: fmt.Sprintf("<%s|%s>", permalink, untranslatedTextPreview),
|
||||||
|
Footer: "g0v Translation Bridge"+b.Config.General.TranslationAttribution,
|
||||||
|
FooterIcon: "https://emoji.slack-edge.com/T02G2SXKM/g0v/541e38dfc833f04b.png",
|
||||||
|
}
|
||||||
|
|
||||||
|
return attach
|
||||||
|
}
|
||||||
|
|
||||||
func extractStringField(data map[string]interface{}, field string) string {
|
func extractStringField(data map[string]interface{}, field string) string {
|
||||||
if rawValue, found := data[field]; found {
|
if rawValue, found := data[field]; found {
|
||||||
if value, ok := rawValue.(string); ok {
|
if value, ok := rawValue.(string); ok {
|
||||||
|
|||||||
@@ -334,7 +334,9 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
msg.ID = ""
|
msg.ID = ""
|
||||||
msg.Text = origmsg.Text
|
msg.Text = origmsg.Text
|
||||||
|
|
||||||
|
// Translation
|
||||||
if (gw.Router.GTClient != nil) && (channel.Options.Locale != "") && (msg.Text != "") {
|
if (gw.Router.GTClient != nil) && (channel.Options.Locale != "") && (msg.Text != "") {
|
||||||
|
msg.TranslationSrcMsg = &origmsg
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
@@ -489,7 +491,11 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
text = html.UnescapeString(text)
|
text = html.UnescapeString(text)
|
||||||
flog.Debugf("post-unescaped:"+text)
|
flog.Debugf("post-unescaped:"+text)
|
||||||
|
|
||||||
|
if dest.Protocol == "slack" {
|
||||||
|
// Attribution will be in attachment for Slack
|
||||||
|
} else {
|
||||||
text = text + gw.Router.General.TranslationAttribution
|
text = text + gw.Router.General.TranslationAttribution
|
||||||
|
}
|
||||||
|
|
||||||
msg.Text = text
|
msg.Text = text
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user