billowy-morning-42410
12/04/2025, 2:22 PMbillowy-morning-42410
12/04/2025, 2:37 PMwide-umbrella-5226
12/04/2025, 3:50 PMbillowy-morning-42410
12/05/2025, 3:25 AMwhite-nest-40686
12/06/2025, 6:57 AMbillowy-morning-42410
12/10/2025, 1:25 PMbillowy-morning-42410
12/10/2025, 1:35 PMwhite-nest-40686
12/10/2025, 2:55 PMwhite-nest-40686
12/10/2025, 2:57 PMwhite-nest-40686
12/10/2025, 2:57 PMbillowy-morning-42410
12/10/2025, 6:33 PMimport React from 'react'
import type { Props } from './schema'
import './styles.css'
// Botpress pasa estas props adicionales cuando el componente se usa en Capture Information
// Basado en el código fuente de @botpress/webchat, el componente recibe sendMessage
interface BotpressProps extends Props {
sendMessage?: (payload: { type: 'text'; text: string; value: string }) => void
}
const Component: React.FC<BotpressProps> = ({
text,
choices = [],
sendMessage
}) => {
// Flag para evitar múltiples envíos por doble click o re-render
const hasSentRef = React.useRef(false)
const [hasSent, setHasSent] = React.useState(false)
const handleChoiceClick = (value: string, label: string) => {
if (hasSentRef.current) {
return
}
hasSentRef.current = true
setHasSent(true)
// Comportamiento nativo: enviar la elección con sendMessage
if (!sendMessage) return
sendMessage({
type: 'text',
text: label, // Label que ve el usuario
value: value // Valor que se guarda en Workflow
})
}
return (
<div className="custom-menu">
{text && <div className="custom-menu-text">{text}</div>}
{choices.length > 0 && (
<div className="custom-menu-choices">
{choices.map((choice, index) => (
<button
key={index}
className="custom-menu-choice"
onClick={() => handleChoiceClick(choice.value, choice.label)}
data-value={choice.value}
data-label={choice.label}
aria-label={choice.label}
disabled={hasSent}
type="button"
>
<span className="choice-label">{choice.label}</span>
</button>
))}
</div>
)}
</div>
)
}
export default Componentbillowy-morning-42410
12/10/2025, 6:41 PMwhite-nest-40686
12/12/2025, 6:15 AMbillowy-morning-42410
12/13/2025, 2:18 AMwooden-beard-40210
12/13/2025, 8:52 PMbillowy-morning-42410
12/14/2025, 2:02 PMbillowy-morning-42410
12/18/2025, 2:06 PM