Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically calling verbs. #10

Closed
brentonannan opened this issue Dec 13, 2015 · 4 comments
Closed

Dynamically calling verbs. #10

brentonannan opened this issue Dec 13, 2015 · 4 comments

Comments

@brentonannan
Copy link

Hi Daniel,

I'm having some trouble trying to build a menu dynamically from an attribute, e.g.:

  @menu_items [
    {"1", "first option"},
    {"2", "second option"},
  ]

  def menu(params) do
    twiml do
      gather numDigits: "1", method: "GET" do
        @menu_items |> Enum.each fn ({number, option_text}) ->
          say "For #{option_text} press #{number}."
        end
      end 
    end 
  end

The error I'm getting is:

** (CompileError) lib/telephone_provisioner/call_flows/job/details.ex:15: cannot invoke remote function ExTwiml.Utilities.create_tag/3 inside match

My guess is that it has something to do with metaprogramming, but I'm new enough to that side of elixir that I can't quite figure out how ex_twiml works. Is there a way you've used successfully for doing such a thing?

Cheers,
Brenton.

@danielberkompas
Copy link
Owner

That definitely sounds like a bug. I will look into it tomorrow morning.

Sent from my iPhone

On Dec 12, 2015, at 8:26 PM, Brenton Annan notifications@github.com wrote:

Hi Daniel,

I'm having some trouble trying to build a menu dynamically from an attribute, e.g.:

@menu_items [
{"1", "first option"},
{"2", "second option"},
]

def menu(params) do
twiml do
gather numDigits: "1", method: "GET" do
@menu_items |> Enum.each fn ({number, option_text}) ->
say "For #{option_text} press #{number}."
end
end
end
end
The error I'm getting is:

** (CompileError) lib/telephone_provisioner/call_flows/job/details.ex:15: cannot invoke remote function ExTwiml.Utilities.create_tag/3 inside match
My guess is that it has something to do with metaprogramming, but I'm new enough to that side of elixir that I can't quite figure out how ex_twiml works. Is there a way you've used successfully for doing such a thing?

Cheers,
Brenton.


Reply to this email directly or view it on GitHub.

@danielberkompas
Copy link
Owner

@brentonannan I figured out the problem. The problem is the fact that you're using "number" as the name of one of your variables in fn. "number" is also the name of a TwiML verb, so the compiler is getting confused, thinking that you want to expand the "number" macro there.

If you change the "number" variable name to "num", it should work. I'll be working on a more friendly error message that will explain this problem.

@brentonannan
Copy link
Author

brentonannan commented Dec 14, 2015 via email

danielberkompas added a commit that referenced this issue Dec 14, 2015
As mentioned in #10, you cannot use a TwiML verb name as a parameter in
a function definition, like this:

```elixir
Enum.each [1, 2] fn(number) ->
  say "Press #{number}"
end
```

This commit adds a nice warning message if a user attempts to do this,
telling them that the "number" verb is reserved.
@danielberkompas
Copy link
Owner

@brentonannan I released a new version, 2.0.1, which will warn about using reserved TwiML verb names as variables in function arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants