Skip to content

Commit

Permalink
Merge pull request #410 from rusq/i406
Browse files Browse the repository at this point in the history
Viewer: polly messages
  • Loading branch information
rusq authored Jan 18, 2025
2 parents 5ec4412 + 0c17e20 commit 303b24a
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ cmd/sdconv/sdconv
/TODO.*
/*.txt
*~
*.swp
.env
*.cache
*.log
Expand Down
15 changes: 15 additions & 0 deletions internal/viewer/renderer/fixtures/polly.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<pre class="slack-section-text">*Test Poll #406*</pre><div class="slack-actions"><BUTTON alt="PollMessage(j2vEyaqwEwErYhA2Y).VotingButton(0)">Monday</BUTTON><BUTTON alt="PollMessage(j2vEyaqwEwErYhA2Y).VotingButton(1)">Tuesday</BUTTON><BUTTON alt="PollMessage(j2vEyaqwEwErYhA2Y).VotingButton(2)">Wednesday</BUTTON><BUTTON alt="PollMessage(j2vEyaqwEwErYhA2Y).VotingButton(3)">Thurdsday</BUTTON><BUTTON alt="PollMessage(j2vEyaqwEwErYhA2Y).VotingButton(4)">Friday</BUTTON></div><pre class="slack-section-text">Monday

`█████████████████████████` | 100% (1)

<@UHSD97ZA5>
Tuesday

`⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ` | 0% (0)</pre><pre class="slack-section-text">Wednesday

`⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ` | 0% (0)
Thurdsday

`⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ` | 0% (0)</pre><pre class="slack-section-text">Friday

`⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ` | 0% (0)</pre>*Total Votes*: 1<div class="slack-actions"><BUTTON alt="PollMessage(j2vEyaqwEwErYhA2Y).ViewAllResponsesButton">View All Responses </BUTTON></div>Sender: Maybe Peter | :unlock: *Responses:* Non-Anonymous | *:clock930: Closes: *<!date^1737765162^{date_short} at {time}|Jan 25, 2025 at 00:32 AM>
195 changes: 195 additions & 0 deletions internal/viewer/renderer/fixtures/polly.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
{
"type": "message",
"user": "U089AJ964TE",
"text": "*Maybe Peter* (Polly Sender: \u003c@UHSD97ZA5\u003e) has a polly for you!",
"ts": "1737160363.583369",
"edited": {
"user": "B089LPE68BB",
"ts": "1737160371.000000"
},
"bot_id": "B089LPE68BB",
"bot_profile": {
"app_id": "A04E6JX41",
"icons": {
"image_36": "https://avatars.slack-edge.com/2020-10-26/1466083688641_05afc842ead4d799a4fc_36.png",
"image_48": "https://avatars.slack-edge.com/2020-10-26/1466083688641_05afc842ead4d799a4fc_48.png",
"image_72": "https://avatars.slack-edge.com/2020-10-26/1466083688641_05afc842ead4d799a4fc_72.png"
},
"id": "B089LPE68BB",
"name": "Polly",
"team_id": "THY5HTZ8U",
"updated": 1737160196
},
"team": "THY5HTZ8U",
"replace_original": false,
"delete_original": false,
"metadata": {
"event_type": "",
"event_payload": null
},
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Test Poll #406*",
"verbatim": true
},
"block_id": "xv7cA",
"accessory": {
"type": "overflow",
"action_id": "PollMessage(j2vEyaqwEwErYhA2Y).PollMessageOverflowMenu()",
"options": [
{
"text": {
"type": "plain_text",
"text": "Settings",
"emoji": true
},
"value": "settings"
}
]
}
},
{
"type": "actions",
"block_id": "2BTuw",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Monday",
"emoji": true
},
"action_id": "PollMessage(j2vEyaqwEwErYhA2Y).VotingButton(0)",
"value": "one"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Tuesday",
"emoji": true
},
"action_id": "PollMessage(j2vEyaqwEwErYhA2Y).VotingButton(1)",
"value": "two"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Wednesday",
"emoji": true
},
"action_id": "PollMessage(j2vEyaqwEwErYhA2Y).VotingButton(2)",
"value": "three"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Thurdsday",
"emoji": true
},
"action_id": "PollMessage(j2vEyaqwEwErYhA2Y).VotingButton(3)",
"value": "four"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Friday",
"emoji": true
},
"action_id": "PollMessage(j2vEyaqwEwErYhA2Y).VotingButton(4)",
"value": "five"
}
]
},
{
"type": "section",
"block_id": "nl1gk",
"fields": [
{
"type": "mrkdwn",
"text": "Monday \n\n`█████████████████████████` | 100% (1)\n\n\u003c@UHSD97ZA5\u003e",
"verbatim": true
},
{
"type": "mrkdwn",
"text": "Tuesday \n\n`⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ` | 0% (0)",
"verbatim": true
}
]
},
{
"type": "section",
"block_id": "fmNoP",
"fields": [
{
"type": "mrkdwn",
"text": "Wednesday \n\n`⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ` | 0% (0)",
"verbatim": true
},
{
"type": "mrkdwn",
"text": "Thurdsday \n\n`⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ` | 0% (0)",
"verbatim": true
}
]
},
{
"type": "section",
"block_id": "YdkD+",
"fields": [
{
"type": "mrkdwn",
"text": "Friday \n\n`⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ` | 0% (0)",
"verbatim": true
}
]
},
{
"type": "context",
"block_id": "2ZI/p",
"elements": [
{
"type": "mrkdwn",
"text": "*Total Votes*: 1",
"verbatim": true
}
]
},
{
"type": "actions",
"block_id": "7kaNy",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View All Responses ",
"emoji": true
},
"action_id": "PollMessage(j2vEyaqwEwErYhA2Y).ViewAllResponsesButton"
}
]
},
{
"type": "divider",
"block_id": "Vx4ym"
},
{
"type": "context",
"block_id": "2dckx",
"elements": [
{
"type": "mrkdwn",
"text": "Sender: Maybe Peter | :unlock: *Responses:* Non-Anonymous | *:clock930: Closes: *\u003c!date^1737765162^{date_short} at {time}|Jan 25, 2025 at 00:32 AM\u003e",
"verbatim": true
}
]
}
]
}
2 changes: 1 addition & 1 deletion internal/viewer/renderer/slack_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (*Slack) mbtAction(ib slack.Block) (string, string, error) {
for _, e := range b.Elements.ElementSet {
switch e := e.(type) {
case *slack.ButtonBlockElement:
fmt.Fprintf(&buf, `[BUTTON: %s: %s]`, e.ActionID, e.Text.Text)
fmt.Fprintf(&buf, `<BUTTON alt="%s">%s</BUTTON>`, e.ActionID, e.Text.Text)
default:
fmt.Fprintf(&buf, "[ELEMENT: %T]", e)
}
Expand Down
8 changes: 8 additions & 0 deletions internal/viewer/renderer/slack_fixtures_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package renderer

import (
_ "embed"
"encoding/json"
"testing"

Expand Down Expand Up @@ -441,3 +442,10 @@ const (
"blocks": null
}`
)

var (
//go:embed fixtures/polly.json
fxtrPolly string
//go:embed fixtures/polly.html
fxtrPollyHTML string
)
16 changes: 15 additions & 1 deletion internal/viewer/renderer/slack_section.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package renderer

import (
"strings"

"github.com/rusq/slack"
)

Expand All @@ -20,5 +22,17 @@ func (*Slack) mbtSection(ib slack.Block) (string, string, error) {
if !ok {
return "", "", NewErrIncorrectType(&slack.SectionBlock{}, ib)
}
return pre("slack-section-text", b.Text.Text), "", nil
if b.Text != nil {
return pre("slack-section-text", b.Text.Text), "", nil
}
if len(b.Fields) > 0 {
var buf strings.Builder
text := make([]string, len(b.Fields))
for i, f := range b.Fields {
text[i] = f.Text
}
buf.WriteString(pre("slack-section-text", strings.Join(text, "\n")))
return buf.String(), "", nil
}
return "", "", nil
}
11 changes: 11 additions & 0 deletions internal/viewer/renderer/slack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/rusq/slack"

"github.com/rusq/slackdump/v3/internal/viewer/renderer/functions"
)

Expand Down Expand Up @@ -64,6 +65,16 @@ func TestSlack_Render(t *testing.T) {
},
template.HTML(`<div class="slack-call">(Call)</div><pre class="slack-section-text">Meeting passcode: yyyyy</pre>`),
},
{
"polly message",
&Slack{
tmpl: tmpl,
},
args{
m: loadmsg(t, fxtrPolly),
},
template.HTML(fxtrPollyHTML),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 303b24a

Please sign in to comment.