I want to trigger a new WhatsApp chat via a webhoo...
# 🌎general
p
I want to trigger a new WhatsApp chat via a webhook. In the webhook, data from a form is to be submitted. In the next step, the bot sends the initial template that the user has to respond to in order to start the chat. In the chat, the user is supposed to answer questions. After the chat is over, the information is to be sent via email. Can anyone help me?
has anyone an idea?
g
Interesting, would like to hear this as awell
s
Hello @prehistoric-secretary-45200 and @gifted-thailand-51685 - @famous-jewelry-85388 is working on something.
++ @bright-magazine-792
p
Hey @steep-wire-96122 , thats great 🙂
Can you give us more detail?
@famous-jewelry-85388 do you have more details?
f
Hi @prehistoric-secretary-45200 there is an issue we are working on now that doesn't allow us to share context between channels.
However, as a workaround, the form can call the WhatsApp API directly and start the chat, however when the user replies back to WhatsApp, Botpress will take the conversation
so: 1- Form sends API request to WhatsApp about the template the user need to fill 2- The user fill and sends it 3- WhatsApp picks the message, check the configuration, founds the Botpress WhatsApp webhook configured 4- WhatsApp sends t he information to the Bot as if it is a message coming from the user 5- The bot starts and process the message and creates a conversation and replies back to the user
I hope that helps
p
@famous-jewelry-85388 Can you tell me what will be changed?
q
Hey! I'm trying to do something similar. I'm trying to build a whatsapp chatbot, When a new row is created in a google sheet, I need the bot to get the phone number and name from the sheet and message them. Is this possible?
p
@famous-jewelry-85388 currently I plan to solve it via a webhook trigger with codeblock. As the webhook does not currently create a conversation, I can take the payload and "send" my form data through it. As soon as the webhook is called, I create a conversation with a whatsapp template via the botpress api. I save the payload in a table. In the conversation I can collect all further data. At the end I can then take the collected data and the data from the table and send them together by mail.
@famous-jewelry-85388 i have now implemented my source code. unfortunately it does not work as expected. Creating the conversation works, but the rest of the source code in the forEach is not executed.
Copy code
typescript
const createConversationWithWhatsApp = async (phoneNumber) => {
    const url = 'https://api.botpress.cloud/v1/chat/conversations/get-or-create';
    const payload = {
        channel: "channel",
        integrationName: "whatsapp",
        tags: {
            "whatsapp:userPhone": phoneNumber,
            "whatsapp:templateName": "test_template",
            "whatsapp:templateLanguage": "de"
        }
    };
    const header = {
        headers: {
            'Content-Type': 'application/json',
            Authorization: 'Bearer xxxx',
            'x-bot-id': event.botId
        }
    };

    const {data} = await axios.post(url, payload, header);

    console.log(data);

    return data.conversation.id;
}

const queueEntries = await queueTable.findRecords({});

const activeNumbers = queueEntries.filter(e => e.conversationId).map(e => e.phoneNumber);

// Filter the entries where no conversation is started
const filteredEntries = queueEntries.filter(e => !e.conversationId && !activeNumbers.includes(e.phoneNumber));

// Filter to get only one item per phoneNumber
const uniqueEntries = _.uniqBy(filteredEntries, 'phoneNumber');

uniqueEntries.forEach(async e => {
    const response = await createConversationWithWhatsApp(e.phoneNumber);

    console.log("forEach works");

    queueTable.updateRecord(e.id, {conversationId: response.conversation.id});
});
@steep-wire-96122 @famous-jewelry-85388 what is the best way to get support for this?
375 Views