Skip to content

Problem serialising VoicePrompt structs to XML #298

@settermjd

Description

@settermjd

While creating Go TwiML examples for the docs, I noticed that the Prompt tag is not serialised to XML correctly. This is because the tag's for attribute is written incorrectly as for_.

For example, take the following, correct, XML:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Pay>
   <Prompt for="payment-card-number">
     <Say>Please enter your 16 digit Visa or Mastercard number.</Say>
   </Prompt>
  </Pay>
</Response>

For example, take the code below. We would reasonably expect it to generate the XML above:

package main

import (
	"fmt"

	"github.com/twilio/twilio-go/twiml"
)

func main() {
	twiml, _ := twiml.Voice([]twiml.Element{
		&twiml.VoicePay{
			InnerElements: []twiml.Element{
				&twiml.VoicePrompt{
					For_: "payment-card-number",
					InnerElements: []twiml.Element{
						&twiml.VoiceSay{
							Message: "Please enter your 16 digit Visa or Mastercard number.",
						},
					},
				},
			},
		},
	})

	fmt.Print(twiml)
}

Unfortunately, it won't, as you can see below:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Pay>
    <Prompt for_="payment-card-number">
      <Say>Please enter your 16 digit Visa or Mastercard number.</Say>
    </Prompt>
  </Pay>
</Response>

The serialisation process needs to be corrected to write the for attribute correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions