Starting a conversation through the API
# 🤝help
e
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
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
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
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
@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
@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
@straight-secretary-60237 yes !
e
that would be amazing! I sure do
So triggers will be manageable from the Studio too? 🚀
r
yup !
i'll ping you a bit later this week (hopefully tomorrow) to gie you early access!
e
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
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
Alrighty, thanks a lot!
a
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
yes that should work @average-megabyte-82737
but we also support whatsapp natively
i
Hi Mike, is this feature now available? I can't seem to find it in the docs?
c
@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
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
Yes, you could if we add a new trigger on the Whatsapp integration to send a template message.
i
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
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.
366 Views