https://discord.gg/botpress logo
#🤝help
Starting a conversation through the API
# 🤝help
e

early-train-33247

05/31/2023, 4:53 PM
Is there a way to have the bot start a conversation, instead of the user? I want to send WhatsApp notifications through Botpress to users of my system that may not have talked to my bot yet. I have a scheduled job in my server that checks if there are any events in the following day. If it does, it will send a WhatsApp to the users related to the event. So when the functions runs I list all conversations and find the first where the whatsapp:userPhone tag is the same phone as I have on my database. If there is a conversation, I just send a new message. But if there isn't a conversation already, I would like to start one. I am not able to do it like this
Copy code
ts
            const createConversationBody: CreateConversationBodyBP = {
                channel: 'channel',
                tags: {
                    'whatsapp:userPhone': phone,
                },
                integrationName: 'whatsapp',
            };

            const createConversationRequest = await axios.post<CreateConversationResponseBP>(
                'conversations',
                createConversationBody,
            );
I get an error saying
'Bot "id" cannot create conversations for channel "channel" of integration "b98f4c5f-cfed-4e47-b45e-c6e2c9415a78"'
Question 1 - Is there a way to achieve this? Or the user must always have start the conversation himself? Question 2 - How can I send a template message in cases where there is a conversation already, but the last interaction was over 24 hours before? (I am thinking of sending a greeting everyday to keep the conversation window always open, is it viable?)
a

acceptable-gold-88171

05/31/2023, 5:03 PM
1) Welcome messages or welcome screens depend on the platform. Just had a quick look at Whatsapp docs but couldn't find anything about that. If you can find one, I think you will be able to accomplish your use case https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-messages 2) We are still working on the API endpoint to create messages. As far as I know the ETA on that would be sometime next week.
e

early-train-33247

05/31/2023, 11:59 PM
Hey Patrick, thanks for the reply! 🙌 1️⃣ I found out I can start a conversation by sending a template message. I would need to simply send a request to Meta Cloud API with the proper data. However I wouldn't have the record of that message when managing the conversation in my Inbox. How do you propose I solve this lack of context? I see two paths *first *- Figuring out how to (or adding a feature to) send payloads from the Botpress API. The template data would be sent in the payload parameter like we do with text. I guess it would probably require a feature to create a conversation by sending a message template to a specific number. Or otherwise fixing the issue I mentioned before. *second *- when listing the messages of a Botpress conversation, also include the ones sent directly to Meta API, to see the full context always. This is an honest workaround, but I feel using Botpress makes more sense and it wouldn't require us to store the messages in a database (I do this already though). 2️⃣ Do you mean that we will soon be able to send templates and media messages from the Botpress API? That would partly solve my problem. Because I can send messages using the API already, but only for existing conversations and I need the templates to start one. Cheers!
Hey @rich-battery-69172 any thoughts or estimates on these matters? Thanks
c

colossal-egg-20510

06/05/2023, 2:12 PM
you should be able to do it the way you tried to.
I would recommend using our Client on npm to use our api. https://www.npmjs.com/package/@botpress/client
r

rich-battery-69172

06/05/2023, 9:37 PM
@early-train-33247 we should ship triggers in the next couple of days, i'm happy to give you early access, as early as wednesday for feedback! triggers will allow you to start conversations programmatically and also support time-based triggers for reviving conversations after X time
let me know if you want early access and i can set this up for you in DM
s

straight-secretary-60237

06/06/2023, 3:39 AM
@rich-battery-69172 These triggers will be great. Im using the botpress cloud. Are cloud userslooking like we will have the same timeline for triggers being released also?
r

rich-battery-69172

06/06/2023, 12:36 PM
@straight-secretary-60237 yes !
e

early-train-33247

06/06/2023, 1:14 PM
that would be amazing! I sure do
So triggers will be manageable from the Studio too? 🚀
r

rich-battery-69172

06/06/2023, 1:42 PM
yup !
i'll ping you a bit later this week (hopefully tomorrow) to gie you early access!
e

early-train-33247

06/06/2023, 1:43 PM
Alrighty then. thanks
Hey @colossal-egg-20510, thanks for letting me know about the client!! I updated my code to use it, but I am still getting an error with code: 403, description: "The requested action can't be peform by this resource", and message "Bot cannot create conversations for channel "channel" of integration "b98f4c5f-cfed-4e47-b45e-c6e2c9415a78"". So I don't think the issue is with the request... I couldn't find anything on the documentation about the possible values of the 'channel' parameter though, could it be the problem? 🤔
c

colossal-egg-20510

06/08/2023, 2:08 PM
oh just took a look and the whatsapp integration didn`t implement the proactive conversation creation. We will take care of adding it soon I will keep you updated! 🚀
e

early-train-33247

06/08/2023, 8:45 PM
Alrighty, thanks a lot!
a

average-megabyte-82737

06/21/2023, 12:12 PM
Good afternoon gentlemen, would you be able to advise if this conversation initiation would work if we are integrating with twilio being our middleman to whatsapp? Would we then be able to instigate messages from the bot to numbers if we supplied a list persay to our twilio? Or would you advocate a cleaner way of doing things?
r

rich-battery-69172

06/21/2023, 6:01 PM
yes that should work @average-megabyte-82737
but we also support whatsapp natively
i

incalculable-bird-83091

06/27/2023, 7:20 AM
Hi Mike, is this feature now available? I can't seem to find it in the docs?
c

colossal-egg-20510

06/27/2023, 2:47 PM
@incalculable-bird-83091 The feature is completed once this is merged into master you'll be able to retry and it should work properly: https://github.com/botpress/botpress/pull/12701
e

early-train-33247

06/27/2023, 6:16 PM
Hey Mike, is this already possible with the Triggers? WhatsApp requires that the first message sent by a business is a Template Message, so could I send a JSON payload to a Whats number with no previous conversation?
c

colossal-egg-20510

06/27/2023, 7:04 PM
Yes, you could if we add a new trigger on the Whatsapp integration to send a template message.
i

incalculable-bird-83091

06/28/2023, 7:35 AM
Thank you very much for the info, another question : is this implementation only available when using nodejs client or can messages templates be issued within the cloud studio?
c

colossal-egg-20510

06/28/2023, 9:40 PM
The triggers are now available through the studio. You can use them as much as you want but like I said we need to add the trigger first to make it available. Once implemented and merge on master this will be available to everyone instantly.
234 Views