2017-04-11 23 views
2

我無法使用quickreplies工作在node-wit messenger.js示例中。 我試過5月的事情,包括:更新了此行的代碼我們的機器人動作(messenger.js 1)):quickreplies編碼node-wit示例messenger.js

const actions = { send({sessionId}, {text,quickreplies}) 

2)和更新的這行代碼我們的機器人動作(messenger.js):

return fbMessage(recipientId, text,quickreplies) 

3)更新我的自定義操作中messenger.js:

getWelcome({context, entities}) 
{ 
     context.welcome = "how are you. Please select from the options below"; 
    context.welcome.quickreplies = [ 
    { 
     title: 'Choice A', 
     content_type: 'text', 
     payload: 'empty' 
    }, 
    { 
     title: 'Choice B', 
     content_type: 'text', 
     payload: 'empty' 
    }, 
    ] 

return context; 
    }, 

4)我嘗試了許多排列。我不能讓它與node-wit messenger.js例子一起工作。快速repliess不顯示我搜索並閱讀所有的文檔

5)你能在這方面幫助,也正是如何檢索messenger.js選擇的快速回復

感謝

回答

0

很抱歉,如果它是晚了,但我猜你正在尋找這樣的:

send(request, response) { 
    const {sessionId, context, entities} = request; 
    let {text, quickreplies} = response; 
    if(text.substring(0,6) === IDENTIFY_PAYLOAD){ 
    text = text.substring(6); // It is a payload, not raw text 
    } else { 
    text = {"text": text}; 
    } 
    if(typeof quickreplies !== "undefined"){ 
    text.quick_replies = response.quickreplies 
     .map(x => { return { 
     "title": x, "content_type": "text", "payload": "empty"} 
    }); 
    } 
} 

我所做的是發送帶有標識一個字符串的有效載荷是不是原始文本(這就是爲什麼我使用的標識符的有效載荷),然後在發送操作我收到兩個參數需要est和迴應,並且我得到他們的屬性。最後,我使用我在互聯網上找到的例程來轉換有效載荷參數,事實上,它可以很好地映射快速回復。