create_payment_prompt

View as MarkdownOpen in Claude

Static helper that builds a payment prompt object for use with the prompts parameter of pay(). Payment prompts customize the TTS messages played during different stages of payment collection.

Parameters

for_situation
strRequired

The payment stage this prompt applies to (e.g., "payment-card-number", "expiration-date", "security-code", "postal-code").

actions
list[dict[str, str]]Required

List of prompt actions. Use create_payment_action() to build each entry.

card_type
Optional[str]Defaults to None

Space-separated card types this prompt applies to (e.g., "visa mastercard").

error_type
Optional[str]Defaults to None

Space-separated error types this prompt handles.

Returns

dict[str, Any] — prompt dictionary to pass in the prompts list of pay().

Example

1from signalwire import AgentBase
2from signalwire import FunctionResult
3
4agent = AgentBase(name="my-agent", route="/agent")
5agent.set_prompt_text("You are a helpful assistant.")
6
7@agent.tool(name="collect_card", description="Collect card payment")
8def collect_card(args, raw_data):
9 prompt = FunctionResult.create_payment_prompt(
10 for_situation="payment-card-number",
11 actions=[
12 FunctionResult.create_payment_action("Say", "Please enter your credit card number.")
13 ]
14 )
15 return (
16 FunctionResult("I'll collect your payment now.")
17 .pay(
18 payment_connector_url="https://api.example.com/pay",
19 charge_amount="49.99",
20 prompts=[prompt]
21 )
22 )
23
24agent.serve()