twilio-java icon indicating copy to clipboard operation
twilio-java copied to clipboard

Issue converting from legacy template to ContentTemplate

Open JamesCThompson opened this issue 10 months ago • 2 comments

Issue Summary

I have been using the SDK to send messages for several years using the now legacy way of providing the contents in the body:

public String sendTextMessage( final String sender, final String receiver, final String body ) {

    PhoneNumber from = new PhoneNumber( "whatsapp:" + sender );
    PhoneNumber to = new PhoneNumber( "whatsapp:" + receiver );

    return Message._creator_( to, from, body )
        .setStatusCallback( callBackUrl )
        .create()
        .getSid();
}

The contents has matched templates that were uploaded to Twilio with placeholders but we had been resolving those placeholders before creating the message.

I have converted the templates through the Twilio UI as per the Upgrading WhatsApp Templates to Content Templates article on the support site.

Following that I have changed the method of send to:

public String sendTextMessage( final String sender, final String receiver, final String contentSid, final Map<String, String> replacements ) {
    
    PhoneNumber from = new PhoneNumber( "whatsapp:" + sender );
    PhoneNumber to = new PhoneNumber( "whatsapp:" + receiver );

    return Message.creator( to, from, contentSid )
        .setContentSid( contentSID ) 
        .setContentVariables( new JSONObject( replacements ).toString() )
        .setStatusCallback( callBackUrl )
        .create()
        .getSid();
}

As per the guide on Send Messages with a Content Template

However I now get com.twilio.exception.ApiException: Twilio could not find a Channel with the specified From address however none of my sender details have changed.

what am I missing in order to update to use the contentSid and continue sending messages from the 1st April?

Technical details:

twilio-java version: 10.6.0 java version: 11

JamesCThompson avatar Mar 27 '25 11:03 JamesCThompson

I should add that I have looked through the docs on the help centre and none of them reference their being any change to the account or senders following the template change.

I can confirm that the sender details are correct as I can run a version of the service using the old payload with the same account & sender configuration.

JamesCThompson avatar Mar 28 '25 14:03 JamesCThompson

@JamesCThompson , Thanks for raising the issue. We will resolve this as soon as possible

manisha1997 avatar Apr 29 '25 12:04 manisha1997