My little snippet used when someone calls us… Feel free to modify for your needs…
This code works in Sweden… but there is probably similar services in other countries that can be used for looking up phonenumbers.
--
-- Uses the swedish number-to-name service 188100.se to lookup who is calling (using Fritz!Box integration)
-- and announce it in your sonos speaker system
--
-- You need to install xpath.lua (found here: http://code.mios.com/trac/mios_genericutils/browser)
-- under /usr/lib/lua/ of your vera unit
--
-- Update the following parameters below:
-- apiKey118100 - Your personal api key requested here: http://utveckling.118100.se/node/10
-- AV_DEV - sonos device id
-- FB_DEV - Fritz!Box device id
-- sayText - Text you want the sonos to say (%s = name of caller)
-- sayLang - Laguage (sv = swedish, en=english, ...)
-- sayVolume - Volume of the announcement
--
local url = require("socket.url")
local xp = require ("xpath")
local lom = require ("lxp.lom")
local http = require('socket.http')
local AV_DEV = 115
local FB_DEV = 122
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local FB_SID = "urn:hek:serviceId:FritzBox1"
local apiKey118100 = "XXXXXXXXXXXXXX.XXXXXXXX"
local serviceUrl = "http://developer.118100.se:8080/openapi-1.1/appetizing?query=%s&key=%s"
local sayTextPrivate = "%s %s is calling"
local sayTextCompany = "The company %s is calling"
local sayLang = "sv"
local sayVolume = 30
local number = luup.variable_get( FB_SID, "Number", FB_DEV)
http.TIMEOUT = 5
luup.log("Incoming number: " .. number)
local result = http.request(string.format(serviceUrl, number, apiKey118100))
local lomobj = lom.parse(result)
local firstName = xpath.selectNodes(lomobj,"//individual/name[@type='first']/text()")[1]
local lastName = xpath.selectNodes(lomobj,"//individual/name[@type='last']/text()")[1]
local company = xpath.selectNodes(lomobj,"//company/name[@type='legal']/text()")[1]
local sayText = ""
if company then
sayText = string.format(sayTextCompany, company)
else
sayText = string.format(sayTextPrivate, firstName, lastName)
end
luup.log("Saying: " .. sayText)
luup.call_action(LS_SID, "Say", {Text = sayText, Language=sayLang, Volume=sayVolume}, AV_DEV)