【问题标题】:Can't we use anything other than displayText from webhook response我们不能使用 webhook 响应中的 displayText 以外的任何东西吗
【发布时间】:2017-04-24 09:23:07
【问题描述】:

我是 api.ai 的新手,我正在做 webhook 的实现。我注意到只有 webhook 响应中的“speech”或“displayText”会显示给用户。是否有任何技术可以使用响应中的任何其他参数?

如果有人告诉我如何设置响应文本的格式,例如加粗、更改字体等,我会很高兴。

谢谢!

【问题讨论】:

    标签: webhooks dialogflow-es


    【解决方案1】:

    请注意,如果您要向其发送响应的客户端(例如 Facebook Messenger)不支持特殊格式(例如粗体),则这是徒劳的练习。

    也就是说,除了纯文本之外,您还可以发送许多更丰富的响应类型,如果您想以编程方式执行此操作而不是在 API.ai 中构建丰富的响应,我建议您在两者之间注入您的自定义服务器端解决方案客户端和 API.ai 而不是在流程结束时拥有它。

    换句话说: 客户端界面 自定义解决方案 API.ai 而不是 客户端 API.ai 自定义实现

    这为您提供了更多自定义和实现选项,包括构建完全自定义的响应/提示逻辑,甚至无需访问 API.ai 端点,或者在处理 API 返回后进一步编辑它们,例如将数据库查询结果附加到API.ai 实现。

    假设您有这样的设置,在 node.js 中,向 Facebook Messenger 发送比文本更高级的有效负载的解决方案如下所示:

    //Send gif or image reply
    function sendGifMessage(recipientId) {
    	var messageData = {
    		recipient: {
    			id: recipientId
    		},
    		message: {
    			attachment: {
    				type: "image",
    				payload: {
    					url: config.SERVER_URL + "FILE LOCATION"
    				}
    			}
    		}
    	};
    
    	callSendAPI(messageData);
    }
    
    // Send custom payload buttons
    function sendButtonMessage(recipientId, text, buttons) {
    	var messageData = {
    		recipient: {
    			id: recipientId
    		},
    		message: {
    			attachment: {
    				type: "template",
    				payload: {
    					template_type: "button",
    					text: text,
    					buttons: buttons
    				}
    			}
    		}
    	};
    
    	callSendAPI(messageData);
    }
    
    // Send quickReply buttons
    function sendQuickReply(recipientId, text, replies, metadata) {
    	var messageData = {
    		recipient: {
    			id: recipientId
    		},
    		message: {
    			text: text,
    			metadata: isDefined(metadata)?metadata:'',
    			quick_replies: replies
    		}
    	};
    
    	callSendAPI(messageData);
    }
    
    function callSendAPI(messageData) {
    	request({
    		uri: 'https://graph.facebook.com/v2.6/me/messages',
    		qs: {
    			access_token: config.FB_PAGE_TOKEN
    		},
    		method: 'POST',
    		json: messageData
    
    	}, function (error, response, body) {
    		if (!error && response.statusCode == 200) {
    			var recipientId = body.recipient_id;
    			var messageId = body.message_id;
    
    			if (messageId) {
    				console.log("Successfully sent message with id %s to recipient %s",
    					messageId, recipientId);
    			} else {
    				console.log("Successfully called Send API for recipient %s",
    					recipientId);
    			}
    		} else {
    			console.error("Failed calling Send API", response.statusCode, response.statusMessage, body.error);
    		}
    	});
    }

    希望有帮助

    【讨论】:

    • 感谢您的帮助。谢谢你:)
    猜你喜欢
    • 1970-01-01
    • 2013-11-05
    • 2021-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多