Hi Community,

 

We are trying to integrate the Zadarma Widget with Creatio. Our main objective is to load this widget every time we press the "Phone" button (marked with red square in the following image).

In order to achieve this, we need to call the necessary dependencies, so it's possible to execute the "zadarmaWidgetFn" function, as you can see on the next image.

require.config({
	paths: {
		loader_phone_lib: '//my.zadarma.com/webphoneWebRTCWidget/v8/js/loader-phone-lib.js?sub_v=62',
		loader_phone_fn: "//my.zadarma.com/webphoneWebRTCWidget/v8/js/loader-phone-fn.js?sub_v=62"
	},
});
 
define("CtiPanel", ["ServiceHelper", "loader_phone_lib", "loader_phone_fn"], function(ServiceHelper) {
	return {
		messages: {},
		mixins: {},
		attributes: {},
		methods: {
			callPhoneNumber: function (){
				var number = this.get("PhoneNumber");
				window.console.log(number);
 
				var sipValue = "SIP";
 
				var payload = {
					sip: sipValue
				};
 
				ServiceHelper.callService("ImdZadarmaWebHookService", "ZadarmaWebRTCKey", function(response) {
					var result = JSON.parse(response.ZadarmaWebRTCKeyResult);
					window.console.log(result.key);
					zadarmaWidgetFn(result.key, 'SIP', 'square', 'en', true, "{left:'10px',top:'5px'}");
				}, payload, this);
			}
		},
		diff: []
	};
});

However, we are getting the following error while loading these dependencies, because one of the files "loader_phone_lib" (https://my.zadarma.com/webphoneWebRTCWidget/v8/js/loader-phone-lib.js?s…) has other dependencies that are called through tags.

We would like to know, how can we load these dependencies, that are inside the "loader_phone_lib" file, without getting this error?

 

Thanks in Advance.

 

Best Regards,

Pedro Pinheiro

Like 3

Like

4 comments

Hi Pedro,

 

According to https://requirejs.org/docs/errors.html#mismatch there should be the anonymous define() method inside the script HTML tag in one of the dependencies that are loaded. So to fix the error you need to check all the steps described in the requirejs.org document.

 

Best regards,

Oscar

Hi Oscar,

 

Thank you for the response.

 

Yes, some of the scripts have the anonymous define() method inside, so by following the documentation you provided, I removed the dependencies from the "loader_phone_lib" script and added them using the code bellow:

....
require.config({
	paths: {
		zadarmaSocket: "//my.zadarma.com/webphoneWebRTCWidget/v8/js/socket.io",
		zadarmaDetectWebRTC: "//my.zadarma.com/webphoneWebRTCWidget/v8/js/detectWebRTC.min",
		zadarmaJssip: "//my.zadarma.com/webphoneWebRTCWidget/v8/js/jssip.min",
		zadarmaMd5: "//my.zadarma.com/webphoneWebRTCWidget/v8/js/md5.min",
		zadarmaWidgetAPI: "//my.zadarma.com/webphoneWebRTCWidget/v8/js/widget-api.min.js?sub_v=62",
		zadarmaWidget: "//my.zadarma.com/webphoneWebRTCWidget/v8/js/widget.min.js?sub_v=62",
		loader_phone_fn: "//my.zadarma.com/webphoneWebRTCWidget/v8/js/loader-phone-fn.js?sub_v=62"
	}
});
 
define("CtiPanel", ["ServiceHelper", "zadarmaSocket", "zadarmaDetectWebRTC", "zadarmaJssip", "zadarmaMd5", "zadarmaWidgetAPI", "zadarmaWidget", "loader_phone_fn"], function(ServiceHelper) {
	return {
		messages: {},
		mixins: {},
		attributes: {},
		methods: {
			callPhoneNumber: function (){
				var number = this.get("PhoneNumber");
				window.console.log(number);
 
				var sipValue = "SIP";
 
				var payload = {
					sip: sipValue
				};
 
				ServiceHelper.callService("ImdZadarmaWebHookService", "ZadarmaWebRTCKey", function(response) {
					var result = JSON.parse(response.ZadarmaWebRTCKeyResult);
					window.console.log(result.key);
					zadarmaWidgetFn(result.key, 'SIP', 'square', 'en', true, "{left:'10px',top:'5px'}");
				}, payload, this);
			}
		},
		diff: []
	};
});

This piece of code manage to "fix" the previous error. However, I'm getting a new error, which is related to the Socket.Io (zadarmaSocket), as you can see on the next image:

I think this error is caused by the fact that one of the dependencies cannot reach specific functions/vars from other dependencies. I've tried to use the "shim" attribute, in order to create a sequence for loading the dependencies and it didn't work.

 

Thanks in Advance.

 

Best Regards,

Pedro Pinheiro

 

Pedro Pinheiro,

 

Hello,

 

The new code returns another error message on my side, but it happens since there is no ImdZadarmaWebHookService service and ZadarmaWebRTCKey method in my app. Can you please also share the code of this part?

 

Thank you!

 

Best regards,

Oscar

Hello Oscar Dylan,

 

The ZadarmaWebRTCKey method is responsible for requesting the WebRTC key from a specific "Client Key", "Client Secret" and SIP Number. I use this key to start the communication between the widget and Zadarma.

 

ImdZadarmaWebHookService.cs

 /* The custom namespace. */
namespace Terrasoft.Configuration.ImdZadarmaWebHookServiceNamespace
{
    using System;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using System.ServiceModel.Activation;
    using Terrasoft.Core;
    using Terrasoft.Web.Common;
    using Terrasoft.Core.Entities; 
	using System.Web;
	using System.Collections.Generic;
	using Terrasoft.Configuration.ImdZadarmaAPI;
	using System.Net.Http;
 
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class ImdZadarmaWebHookService: BaseService
    {
        [OperationContract]
       	[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
		public string ZadarmaWebRTCKey(string sip){
 
            //ZadarmaApi is a class that contains all the methods to work with Zadarma API
			var zadarma = new ZadarmaApi("KEY", "SECRET");
 
 
			SortedDictionary<string, string> parameters = new SortedDictionary<string, string>();			
			parameters.Add("sip", sip);
 
            var response = zadarma.Call("/v1/webrtc/get_key/", parameters, HttpMethod.Get);
            string str = (string) response.Content.ReadAsStringAsync().Result;
            return str;
		}
    }   
}

The code for ZadarmaApi class can be found here:

https://github.com/zadarma/user-api-cs-v1/blob/master/ZadarmaAPI/ZadarmaApi.cs

 

Best Regards,

Pedro Pinheiro

Show all comments