Browse Source

Prevent an error when voicemail box does not exist.

Mark Crane 12 years ago
parent
commit
0ffe14bb22
1 changed files with 55 additions and 48 deletions
  1. 55 48
      includes/install/scripts/app/voicemail/index.lua

+ 55 - 48
includes/install/scripts/app/voicemail/index.lua

@@ -219,56 +219,63 @@
 --leave a message
 	if (voicemail_action == "save") then
 
-		--save the recording
-			timeouts = 0;
-			play_greeting();
-			record_message();
-
-		--save the message to the voicemail messages
-			if (message_length > 2) then
-				local sql = {}
-				table.insert(sql, "INSERT INTO v_voicemail_messages ");
-				table.insert(sql, "(");
-				table.insert(sql, "voicemail_message_uuid, ");
-				table.insert(sql, "domain_uuid, ");
-				table.insert(sql, "voicemail_uuid, ");
-				table.insert(sql, "created_epoch, ");
-				table.insert(sql, "caller_id_name, ");
-				table.insert(sql, "caller_id_number, ");
-				table.insert(sql, "message_length ");
-				--table.insert(sql, "message_status, ");
-				--table.insert(sql, "message_priority, ");
-				table.insert(sql, ") ");
-				table.insert(sql, "VALUES ");
-				table.insert(sql, "( ");
-				table.insert(sql, "'".. uuid .."', ");
-				table.insert(sql, "'".. domain_uuid .."', ");
-				table.insert(sql, "'".. voicemail_uuid .."', ");
-				table.insert(sql, "'".. start_epoch .."', ");
-				table.insert(sql, "'".. caller_id_name .."', ");
-				table.insert(sql, "'".. caller_id_number .."', ");
-				table.insert(sql, "'".. message_length .."' ");
-				--table.insert(sql, "'".. message_status .."', ");
-				--table.insert(sql, "'".. message_priority .."' ");
-				table.insert(sql, ") ");
-				sql = table.concat(sql, "\n");
-				if (debug["sql"]) then
-					freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
-				end
-				dbh:query(sql);
-			end
+		--valid voicemail
+			if (voicemail_uuid ~= nil) then
+
+				--save the recording
+					timeouts = 0;
+					play_greeting();
+					record_message();
+
+				--save the message to the voicemail messages
+					if (message_length > 2) then
+						local sql = {}
+						table.insert(sql, "INSERT INTO v_voicemail_messages ");
+						table.insert(sql, "(");
+						table.insert(sql, "voicemail_message_uuid, ");
+						table.insert(sql, "domain_uuid, ");
+						table.insert(sql, "voicemail_uuid, ");
+						table.insert(sql, "created_epoch, ");
+						table.insert(sql, "caller_id_name, ");
+						table.insert(sql, "caller_id_number, ");
+						table.insert(sql, "message_length ");
+						--table.insert(sql, "message_status, ");
+						--table.insert(sql, "message_priority, ");
+						table.insert(sql, ") ");
+						table.insert(sql, "VALUES ");
+						table.insert(sql, "( ");
+						table.insert(sql, "'".. uuid .."', ");
+						table.insert(sql, "'".. domain_uuid .."', ");
+						table.insert(sql, "'".. voicemail_uuid .."', ");
+						table.insert(sql, "'".. start_epoch .."', ");
+						table.insert(sql, "'".. caller_id_name .."', ");
+						table.insert(sql, "'".. caller_id_number .."', ");
+						table.insert(sql, "'".. message_length .."' ");
+						--table.insert(sql, "'".. message_status .."', ");
+						--table.insert(sql, "'".. message_priority .."' ");
+						table.insert(sql, ") ");
+						sql = table.concat(sql, "\n");
+						if (debug["sql"]) then
+							freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
+						end
+						dbh:query(sql);
+					end
 
-		--set the message waiting event
-			if (message_length > 2) then
-				local event = freeswitch.Event("message_waiting");
-				event:addHeader("MWI-Messages-Waiting", "yes");
-				event:addHeader("MWI-Message-Account", "sip:"..voicemail_id.."@"..domain_name);
-				event:fire();
-			end
+				--set the message waiting event
+					if (message_length > 2) then
+						local event = freeswitch.Event("message_waiting");
+						event:addHeader("MWI-Messages-Waiting", "yes");
+						event:addHeader("MWI-Message-Account", "sip:"..voicemail_id.."@"..domain_name);
+						event:fire();
+					end
 
-		--send the email with the voicemail recording attached
-			if (message_length > 2) then
-				send_email(voicemail_id, uuid);
+				--send the email with the voicemail recording attached
+					if (message_length > 2) then
+						send_email(voicemail_id, uuid);
+					end
+			else
+				--invalid voicemail
+					session:hangup();
 			end
 	end