Welcome Message

If you want to send a welcome message when users enter the conversation page, or send a greeting message when users re-enter the Mini Program after a period of time, you can add the following logic to the createAgent function.

For more detailed information, please visit Customizing Welcome and Greeting Messages.

const createAgent = () => {
  
  const { onChatStart, createMessage, onChatResume } = agent

  // Create an initial welcome message
  onChatStart(async (result) => {
    const hello = createMessage({
      role: 'assistant',
    })

    hello.bubble.setText('Hello') // Define your multilingual greeting here
    
    result.messages.push(hello)
    
    await hello.persist('createText') // Persist this message bubble
  })

  return agent
}