Skip to content

Commit 19e2e92

Browse files
committed
added support to set the <select> title
1 parent bcd36d4 commit 19e2e92

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

bot.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Dialog struct {
4141
type Input struct {
4242
NS string
4343
ID string
44+
Title string
4445
Name string
4546
Type string
4647
Options []*Button

messenger_session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (m *MessengerSession) SendInput(input *Input) error {
9292
cta.Payload = btn.Href
9393
callToActions = append(callToActions, cta)
9494
}
95-
return m.response.ButtonTemplate("Select an option ...", &callToActions, messenger.MessagingType("RESPONSE"))
95+
return m.response.ButtonTemplate(input.Title, &callToActions, messenger.MessagingType("RESPONSE"))
9696
}
9797
return nil
9898
}

messenger_wrapper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (m Messenger) Boot() {
159159

160160
// the required action
161161
needle, _ := url.ParseQuery(p.Payload)
162-
log.Println("[postback]", needle)
162+
log.Println("[postback]", needle, ", ShouldBeInput: ", session.IsExpectingUserInput())
163163

164164
// reset?
165165
if needle.Get("btn") != "" && m.bot.Buttons[needle.Get("btn")] != nil && m.bot.Buttons[needle.Get("btn")].Reset {

parser.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import (
44
"fmt"
55
"io"
66
"strings"
7-
)
87

9-
import (
108
"github.com/PuerkitoBio/goquery"
119
)
1210

@@ -68,6 +66,7 @@ func NewBotFromReader(r io.Reader) (*Bot, error) {
6866
fn := func(i int, n *goquery.Selection) {
6967
input := &Input{}
7068
input.NS = dialog.ID
69+
input.Title = n.AttrOr("title", "Fill/Choose ...")
7170
input.ID = n.AttrOr("id", fmt.Sprintf("input%d", len(bot.Inputs)+1))
7271
input.Name = n.AttrOr("name", input.ID)
7372
input.Value = n.AttrOr("value", "")
@@ -86,7 +85,13 @@ func NewBotFromReader(r io.Reader) (*Bot, error) {
8685
})
8786
bot.Inputs[input.ID] = input
8887
n.SetAttr("id", input.ID)
88+
n.SetAttr("title", input.Title)
8989
}
90+
d.Find("div").Children().Each(func(i int, s *goquery.Selection) {
91+
s.SetAttr("if", s.Parent().AttrOr("if", ""))
92+
s.Parent().BeforeSelection(s.Clone())
93+
})
94+
d.Find("div").Remove()
9095
d.Find("input,select").Each(func(i int, n *goquery.Selection) {
9196
switch strings.ToLower(goquery.NodeName(n)) {
9297
case "input":
@@ -96,11 +101,6 @@ func NewBotFromReader(r io.Reader) (*Bot, error) {
96101
fn(i, n)
97102
}
98103
})
99-
d.Find("div").Children().Each(func(i int, s *goquery.Selection) {
100-
s.SetAttr("if", s.Parent().AttrOr("if", ""))
101-
s.Parent().AfterSelection(s.Clone())
102-
s.Remove()
103-
})
104104
bot.Dialogs[dialog.ID] = dialog
105105
d.SetAttr("id", dialog.ID)
106106
})

0 commit comments

Comments
 (0)