Siga-me manipulável via telefone e via banco de dados no Asterisk

Criação de um sigame que pode posterior manipular via telefone ou interface web

Criar o banco no mysql:

create database asterisk;

use asterisk;

CREATE TABLE IF NOT EXISTS `sigame` (
  `status` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `sigame` (`status`) VALUES (1);

Criar no plano de discagem do asterisk:

/etc/asterisk/extensions.conf


[sigame]

[sigame]


exten => ***,1,goto(sigame,s,1(inicio_sigame))

exten => s,1(inicio_sigame),background(ativa_desativa_sigame)
	
exten => 0,1,playback(fala_zero)
	same => n,goto(sigame_desativado,1)
exten => 1,1,playback(fala_um_sigame)
	same => n,goto(sigame_ativo,1)
exten => 9,1,playback(fala_nove)
	same => n,goto(sigame_consulta,1)

exten => s,2,WaitExten(3)
		same => n,goto(sigame,s,1)
exten => i,1,Playback(opcao_invalida_sigame)
		same => n,goto(sigame,s,1)
exten  => sigame_ativo,1,NooP(Siga-me esta ativado)
		same => n,nocdr()
		same => n,MYSQL(Connect connid localhost root zoltrix90 asterisk)
		same => n,NoOp(connid = ${connid})
		same => n,MYSQL(Query resultid ${connid} update sigame set status=1)
		same => n,MYSQL(Disconnect ${connid})
		same => n,playback(sigame_ativado)
		same => n,goto(sigame,s,1)
exten => sigame_desativado,1,NooP(Siga-me esta desativado)
		same => n,nocdr()
		same => n,MYSQL(Connect connid localhost root zoltrix90 asterisk)
		same => n,NoOp(connid = ${connid})
		same => n,MYSQL(Query resultid ${connid} update sigame set status=0)
		same => n,MYSQL(Disconnect ${connid})
		same => n,playback(sigame_desativado)
		same => n,goto(sigame,s,1)
exten  => sigame_consulta,1,NooP(Consulta Siga-me)
		same => n,MYSQL(Connect connid localhost root zoltrix90 asterisk)
		same => n,NoOp(connid = ${connid})
		same => n,MYSQL(Query resultid ${connid} SELECT status FROM sigame)
		same => n,NoOp(resultid = ${resultid})
		same => n,MYSQL(Fetch fetchid ${resultid} status)
		same => n,NoOp(Variabili = ${fetchid},${status})
		same => n,MYSQL(Clear ${resultid})
		same => n,MYSQL(Disconnect ${connid})
		same => n,noop(Sigame esta com valor --> ${status})


		same => n,GotoIf($["${status}" = "1" ]?sigame_ativo2)
		same => n,GotoIf($["${status}" = "0" ]?sigame_desativado2)
			same => n(sigame_ativo2),NooP(Siga-me esta ativado)
			same => n,nocdr()
			same => n,playback(sigame_ativado2)
			same => n,goto(sigame,s,1)
	same => n(sigame_desativado2),NooP(Siga-me esta desativado)
			same => n,nocdr()
			same => n,playback(sigame_desativado2)
			same => n,goto(sigame,s,1)

[recebe_chamadas]
exten => s,1,Answer(1)
	same => n,MYSQL(Connect connid localhost root zoltrix90 asterisk)
	same => n,NoOp(connid = ${connid})
	same => n,MYSQL(Query resultid ${connid} SELECT status FROM sigame)
	same => n,NoOp(resultid = ${resultid})
	same => n,MYSQL(Fetch fetchid ${resultid} status)
	same => n,NoOp(Variabili = ${fetchid},${status})
	same => n,MYSQL(Clear ${resultid})
	same => n,MYSQL(Disconnect ${connid})
	same => n,noop(Sigame esta com valor --> ${status})

	  same => n,GotoIf($["${status}" = "1" ]?sigame_ativo)
	  same => n,GotoIf($["${status}" = "0" ]?sigame_desativado)
	  
	  same => n(sigame_ativo),NooP(Siga-me esta ativado)
	  
		same => n,Set(CDR(userfield)=SIGA-ME)
		same => n,Set(CDR(original_dst)=SP VIA SIP)
		same => n,nocdr()
		same => n,playback(conectado)
		same => n,Dial(SIP/10600001366/101&SIP/10600001366/102&SIP/10600001366/103,120,r)
		same => n,Goto(${DIALSTATUS})
			same => n(CONGESTION),Dial(dahdi/3/0214133529277,60,r)
			 same => n,Set(CDR(original_dst)=SP VIA ANALOGICA)
			 same => n,Hangup
			same => n(busy/congestion),Dial(dahdi/3/0214133529277,60,r)
			 same => n,Set(CDR(original_dst)=SP VIA ANALOGICA)
			 same => n,Hangup
			same => n(CHANUNAVAIL),Dial(dahdi/3/0214133529277,60,r)
			 same => n,Set(CDR(original_dst)=SP VIA ANALOGICA)
			 same => n,Hangup
			same => n(BUSY),Dial(dahdi/3/0214133529277,60,r)
			 same => n,Set(CDR(original_dst)=SP VIA ANALOGICA)
			 same => n,Hangup

	  same => n(sigame_desativado),NooP(Siga-me esta desativado)
			same => n,Set(CDR(userfield)=Lig. Recebida)
			;same => n,playback(Conectado)
			same => n,Set(CDR(original_dst)=Ramal 201)
			same => n,Dial(SIP/201,22,Tt)
			same => n,Set(CDR(original_dst)=Ramal 202)
			same => n,Dial(SIP/202,90,Tt)
			;same => n,Queue(Fila,tT,,,600)
			same => n,hangup()


	

Pode-se usar a imaginação para manipular via interface web

Deixe uma resposta