Just for others looking later, here is the final code I came up with, with rtp_payload extracted. 

if session:getVariable("switch_r_sdp") ~= nil then
local s = '[[' .. session:getVariable("switch_r_sdp") ..']]'
if string.find(s, "a=rtpmap:(%d+)%stelephone%-event%/8000") ~= nil then

freeswitch.consoleLog("debug", "NO NEED TO START starting spandsp_start_dtmf\n")
local payload = string.match(s,"a=rtpmap:(%d+)%stelephone%-event%/8000")
if payload  ~= nil then
freeswitch.consoleLog("debug", "rtp_payload_number = " .. payload  .."\n")
end 

else

freeswitch.consoleLog("info", "starting spandsp_start_dtmf\n")
session:execute("spandsp_start_dtmf")
session:sleep(2000)
end

end 


Cheers

Phil