public void connect(MessageContext messageContext) throws ConnectException { SynapseLog log = getLog(messageContext); log.auditLog("Start: create account"); String friendlyName = (String) ConnectorUtils.lookupTemplateParamater(messageContext, TwilioUtil.PARAM_FRIENDLY_NAME); // Build a filter for the AccountList Map<String, String> params = new HashMap<String, String>(); // If a friendly name has been provided for the account; // if not will use the current date and time (Default by Twilio). if (friendlyName != null) { params.put(TwilioUtil.TWILIO_FRIENDLY_NAME, friendlyName); } try { TwilioRestClient twilioRestClient = TwilioUtil.getTwilioRestClient(messageContext); AccountFactory accountFactory = twilioRestClient.getAccountFactory(); Account account = accountFactory.create(params); OMElement omResponse = TwilioUtil.parseResponse("account.create.success"); TwilioUtil.addElement(omResponse, TwilioUtil.TWILIO_ACCOUNT_SID, account.getSid()); TwilioUtil.preparePayload(messageContext, omResponse); } catch (Exception e) { log.error(e.getMessage()); TwilioUtil.handleException(e, "0001", messageContext); throw new SynapseException(e); } log.auditLog("End: create account"); }
public void connect(MessageContext messageContext) throws ConnectException { SynapseLog log = getLog(messageContext); log.auditLog("Start: get member"); String queueSid = (String) ConnectorUtils.lookupTemplateParamater(messageContext, TwilioUtil.PARAM_QUEUE_SID); String callSid = (String) ConnectorUtils.lookupTemplateParamater(messageContext, TwilioUtil.PARAM_CALL_SID); try { TwilioRestClient twilioRestClient = TwilioUtil.getTwilioRestClient(messageContext); TwilioRestResponse response = twilioRestClient.request( TwilioUtil.API_URL + "/" + TwilioUtil.API_VERSION + "/" + TwilioUtil.API_ACCOUNTS + "/" + twilioRestClient.getAccountSid() + "/" + TwilioUtil.API_QUEUES + "/" + queueSid + "/" + TwilioUtil.API_MEMBERS + "/" + callSid, "GET", null); OMElement omResponse = TwilioUtil.parseResponse(response); TwilioUtil.preparePayload(messageContext, omResponse); } catch (Exception e) { log.error(e); throw new SynapseException(e); } log.auditLog("End: get member"); }