class FeedbackCollector {
async sendFeedbackRequest(userPhone) {
const response = await client.sendText(
userPhone,
'How was your experience with our service today?'
);
// Store message ID for reaction tracking
this.pendingFeedback.set(response.messages[0].id, {
userPhone,
timestamp: Date.now()
});
}
async handleReactionWebhook(reactionData) {
const { message_id, emoji, from } = reactionData;
if (this.pendingFeedback.has(message_id)) {
const feedback = this.analyzeFeedback(emoji);
await this.storeFeedback(from, feedback);
// Thank with appropriate reaction
if (feedback.rating >= 4) {
await client.reactWithLove(from, message_id);
} else if (feedback.rating >= 3) {
await client.reactWithThumbsUp(from, message_id);
} else {
await client.reactWithSad(from, message_id);
}
}
}
analyzeFeedback(emoji) {
const feedbackMap = {
'😍': { rating: 5, sentiment: 'excellent' },
'❤️': { rating: 5, sentiment: 'love' },
'🔥': { rating: 5, sentiment: 'amazing' },
'👍': { rating: 4, sentiment: 'good' },
'👏': { rating: 4, sentiment: 'satisfied' },
'😊': { rating: 3, sentiment: 'okay' },
'😐': { rating: 2, sentiment: 'neutral' },
'👎': { rating: 1, sentiment: 'poor' },
'😢': { rating: 1, sentiment: 'disappointed' },
'😠': { rating: 1, sentiment: 'angry' }
};
return feedbackMap[emoji] || { rating: 3, sentiment: 'unknown' };
}
}