Trying to get AGI to work / giving instances of MP3Player a diallable number?

asterisk
freepbx
Tags: #<Tag:0x00007f7031f814e0> #<Tag:0x00007f703f46ee78>

(Prehensile) #1

Hello there! I’m a total n00b to FreePBX, but I am a decent web and systems programmer. I’m currently at the stage of attempting to figure out FreePBX / Asterisk via endless googling :wink:

What I’m trying to do
Set up an instance of FreePBX so that calls to a given number (say, 9001) results in playback of an MP3 file or stream to the caller, chosen at random from a list.

What I’ve tried so far

  • Written a Python AGI script, using the pyst2 library, which returns an AGI command to run MP3Player and passes it a file path. Copied the script to /var/lib/asterisk/agi-bin/jukebox.py and chmod to 755.
  • Added the following block to /etc/asterisk/extensions_custom.conf (which I just copypasted from a post on this forum about AGI scripting):
[agi-jukebox-trigger]
exten => s,1,noop(entering context [agi-jukebox-trigger] in extensions_custom.conf)
exten => s,n,AGI(jukebox.py)
exten => s,n,Return
  • Set up a Custom Destination in FreePBX admin with the following Target (again, just copied from the same post as above)
 agi-jukebox-trigger,s,1
  • Added a Custom Extension in FreePBX Admin > Applications > Extensions with the number 9001, and in the Advanced tab, set the Not Reachable Custom Destination to the Custom Destination set up above.

Where I’m stuck
It seems like neither my Python script, nor the entry in extensions_custom.conf are executing. When I call 9001, I can see a reference to the dialplan entry in the logs, but I can’t see the noop from the block in extensions_custom.conf or one that I added to the Python script appear in the logs.

Help me!

  • Is there a better way of invoking the block in extensions_custom.conf / AGI script when a given number is dialled than my current bodge?
  • What might be causing the block to not execute?
  • What are some good debugging strategies that I can use so I don’t have to bother you all again?

(Itzik) #2

Please post the call logs, it will be helpful for us to “see” what’s happening.

https://wiki.freepbx.org/display/SUP/Providing+Great+Debug#ProvidingGreatDebug-AsteriskLogs-PartII

Also, my personal preference is to use a Misc Application instead of a custom extension.


#3

mp3’s can be problematic natively with asterisk, try regular .wav or .WAV or .gsm format files, from the cli

agi set debug on

might be helpful


(Prehensile) #4

Can I post links yet?


(Prehensile) #5

Apologies for terseness in the above post, that was more of a note-to-self than an actual post intended for humans. Which I now can’t edit :frowning:
Anyway, that link is to a Gihub Gist containing the logs. The last few lines look like this:

[2020-09-28 23:24:30] VERBOSE[29965][C-0000000f] pbx.c: Executing [9001@from-internal:5] GotoIf("PJSIP/2001-0000000e", "1? agi-jukebox-trigger,s,1") in new stack
[2020-09-28 23:24:30] VERBOSE[29965][C-0000000f] pbx_builtins.c: Goto ( agi-jukebox-trigger,s,1)
[2020-09-28 23:24:30] WARNING[29965][C-0000000f] pbx.c: Channel 'PJSIP/2001-0000000e' sent to invalid extension but no invalid handler: context,exten,priority= agi-jukebox-trigger,s,1

(Itzik) #6

The link I posted describes how to upload a call trace to pastebin.

Anyways, it seems like you have an extra space in your custom destination.


(Lorne Gaetz) #7
1? agi-jukebox-trigger
  ^

The leading space bugs me, is that there in the custom dest?


(Prehensile) #8

Heh, as it turned out it was the typo / leading space in the destination. Everything else worked fine!

Thanks everyone.


(Lorne Gaetz) #9

It is so easy to get a leading and/or trailing space when doing cut & paste, and it’s impossible to see the spaces when populating GUI fields. Ordinarily, I would recommend a ticket to get this addressed, but it looks like a space is a valid character in an Asterisk context (perhaps @jcolp can confirm) in which case I think this is something we will have to live with.


(Joshua C. Colp) #10

I don’t know if it’s explicitly documented or not as such, but generally the dialplan behavior is very … literal … and not something we’d really want to change.


(Prehensile) #11

Maybe you could do it as a warning on the GUI side? Some kind of popup message which says “looks like your Target contains a space, did you really mean to do that”?

EDIT: Even better, it appears that HTML5 has an ‘onpaste’ event on input fields. So you could attach a function there to check if the pasted text contains spaces, and warn only in that case.


(Lorne Gaetz) #12

Open a feature request pls: https://issues.freepbx.org/


(system) closed #13

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.