twilio / twilio/twilio-java

Issue converting from legacy template to ContentTemplate

Open
#845 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

priority: high
Dominant language
Java
Stars
527
Forks
453
Avg merge
10h 59m
Merged PRs (30d)
6

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Message.creator and Message.creator entry points shown in the report, then review the linked content-template sending guide and compare the legacy and migrated calls. Reproduce the Channel error with twilio-java 10.6.0 on Java 11; done means the migration behavior is explained or an SDK/API correction is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.