From d4818d0a52d0d431404178fbb078878f1cfe6668 Mon Sep 17 00:00:00 2001 From: Mohamed Al Ashaal Date: Sun, 4 Mar 2018 16:16:45 +0200 Subject: [PATCH] removed the inline functionality --- README.md | 4 ++-- messenger_session.go | 25 ++++++++++++------------- parser.go | 10 +++++----- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 8b8916b..21cd842 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Features ==== - Portable & Tiny - Embedded a tiny `Expression Engine` to support simple scripting -- Supports the following tags `meta, text, label, p, line, inline, span, embed, resource, media, div, menu, nav, dialog, form, template` +- Supports the following tags `meta, text, label, p, line, span, embed, resource, media, div, menu, nav, dialog, form, template` - Supports custom replies from custom templates - Automatically paginate long `Menus` to be compatible with messenger `max-items-limit` @@ -57,7 +57,7 @@ Demo Collect Data - + Click Here 1 Click Here 2 diff --git a/messenger_session.go b/messenger_session.go index 2a3bd85..6ab7f37 100644 --- a/messenger_session.go +++ b/messenger_session.go @@ -84,16 +84,15 @@ func (m *MessengerSession) SendInput(input *Input) error { return nil } if input.Type == "options" { - return m.SendInlineButtons(input.Title, input.Options) - // callToActions := []messenger.StructuredMessageButton{} - // for _, btn := range input.Options { - // cta := messenger.StructuredMessageButton{} - // cta.Title = btn.Title - // cta.Type = "postback" - // cta.Payload = btn.Href - // callToActions = append(callToActions, cta) - // } - // return m.response.ButtonTemplate(input.Title, &callToActions, messenger.MessagingType("RESPONSE")) + callToActions := []messenger.StructuredMessageButton{} + for _, btn := range input.Options { + cta := messenger.StructuredMessageButton{} + cta.Title = btn.Title + cta.Type = "postback" + cta.Payload = btn.Href + callToActions = append(callToActions, cta) + } + return m.response.ButtonTemplate(input.Title, &callToActions, messenger.MessagingType("RESPONSE")) } return nil } @@ -103,9 +102,9 @@ func (m *MessengerSession) SendBasicMenu(menu *Menu) error { if menu == nil { return nil } - if menu.Inline { - return m.SendInlineButtons(menu.Title, menu.Buttons) - } + // if menu.Inline { + // return m.SendInlineButtons(menu.Title, menu.Buttons) + // } callToActions := []messenger.StructuredMessageButton{} for _, btn := range menu.Buttons { cta := messenger.StructuredMessageButton{} diff --git a/parser.go b/parser.go index 453b997..90dc43c 100644 --- a/parser.go +++ b/parser.go @@ -38,18 +38,18 @@ func NewBotFromReader(r io.Reader) (*Bot, error) { // paginate the menu/navs buttons // messanger maximum navigation links are 3 - 4, we will make them 3 by maximum. doc.Find("menu,nav").Each(func(_ int, m *goquery.Selection) { - m.SetAttr("inline", m.AttrOr("inline", "false")) - if m.AttrOr("inline", "false") == "true" { - return - } if m.AttrOr("id", "") == bot.Configs["main-menu"] { return } p, cnt := m, 1 + more := bot.Configs["pager-more"] + if more == "" { + more = "More" + } m.Find("a,button").Each(func(i int, b *goquery.Selection) { if (i > 0) && (i%2 == 0) && m.Find("a,button").Length() > 3 { newId := fmt.Sprintf("%s-%d", m.AttrOr("id", ""), cnt) - p.AppendHtml(fmt.Sprintf("%s", newId, "More")) + p.AppendHtml(fmt.Sprintf("%s", newId, more)) p.AfterHtml(fmt.Sprintf("", newId, m.AttrOr("title", ""))) p = bot.Document.Find("#" + newId) cnt++