Skip to content

Instantly share code, notes, and snippets.

@hugochinchilla
Created November 25, 2015 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugochinchilla/821194c2f491c089358c to your computer and use it in GitHub Desktop.
Save hugochinchilla/821194c2f491c089358c to your computer and use it in GitHub Desktop.
SFLphone handler for "callto" or "tel" urls, uses the first enabled SIP account to place the call.
#!/usr/bin/env python
from os.path import expanduser
from os import popen
from yaml import load as load_yaml
from random import randint
from sys import argv
import re
import sys
CONFIG=expanduser("~/.config/sflphone/sflphoned.yml")
IGNORE_ACCOUNTS=['IP2IP', 'local fs']
def get_accounts():
with open(CONFIG) as conf:
return load_yaml(conf)['accounts']
def find_first_active_account_id(accounts):
for account in accounts:
if account['alias'] in IGNORE_ACCOUNTS:
continue
if account['enable']:
return account['id']
def generate_random_callid():
return randint(1000,100000)
if __name__ == '__main__':
if len(argv) < 2:
print("Error: argument 1 (phone number) not provided.")
sys.exit(1)
elif len(argv) > 2:
print("Unexpected argument after phone")
call_to = re.sub('[^0-9]', '', argv[1])
account_id = find_first_active_account_id(get_accounts())
call_id = generate_random_callid()
print("Calling to {} from {}".format(call_to, account_id))
# easier to use dbus-send than the dbus interface for python
popen("""
dbus-send \
--type="method_call" \
--dest="org.sflphone.SFLphone" \
"/org/sflphone/SFLphone/CallManager" \
"org.sflphone.SFLphone.CallManager.placeCall" \
string:"{}" \
string:"{}" \
string:"{}" """.format(account_id, call_id, call_to))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment