I wanted to store a JSON object between agi requests for the duration of a call.
Turns out asterisk does NOT like a stringified JSON object! AGI complains of "520-Invalid command syntax" So, I just base64 encode/decode it. Assuming I don't need to manipulate the JSON object within Asterisk itself, and I don't want to use a DB or memcache, is this the best/correct method? WARNING! Asterisk truncates long variables - seems to be about 3000 characters or so(?), so make sure your base64 encoded object is small! The following is a simple example which just encodes and decodes the agi variables themselves as they're an object in ts-agi (I'm using the ts-agi node package here as an example - https://github.com/sergey12313/ts-agi/ ) await ctx.setVariable('testvar2', Buffer.from(JSON.stringify(ctx.variables), 'utf8').toString('base64')) const testvar2 = (await ctx.getVariable('testvar2')).value const decoded = JSON.parse(Buffer.from(testvar2, 'base64').toString('utf8')) console.log('decoded is', decoded) Hope this helps someone!
-- _____________________________________________________________________ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- Check out the new Asterisk community forum at: https://community.asterisk.org/ New to Asterisk? Start here: https://wiki.asterisk.org/wiki/display/AST/Getting+Started asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users