To begin, I am performing outbound calling. What I'm attempting to do is dynamically create a questionnaire/survey based on parameters that are posted to my start_url -- these will be put into the call_parameters. My database consists of tables of questions and tables of possible answer choices (I'm simplifying this, obviously); a question, of course, can/will have multiple answer choices.
I can successfully initiate a call and post a call_parameter to my start_url. I can then, in my code behind query my database and even have the application call me and say the questionnaire greeting to me. I am also, in code behind, able to get a list of questions...however it's there that I run into problems. I am not sure how then transfer this list from my code behind into a vxml and then iterate through each question and present the possible choices...
My issues are--I need to do this dynamically because each questionnaire may be different, therefore the questions/answers may be different and therefore I do not know how many questions I will be processing. I was thinking to create an XML document and using the data tag...however I'm running into difficulties doing this as well. I'm thinking I possibly call this in the wrong place as I create the xml document in the same code behind and the same page..and I also do not save it to my server, I simply pass it in memory...
Any guidance, examples, assistance would be greatly appreciated.
Currently this is what I have:
ASPX Code
Code: Select all
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="playGreeting.aspx.cs" Inherits="PVTest.playGreeting" %>
<%
Response.ContentType = "text/xml";
%><?xml version='1.0'?>
<vxml version="2.0">
<var name="callParam" expr =" '<% =Request["callParams"] %>'" />
<form id="Welcome">
<block>
<prompt>
Call Params are: <value expr="callParam" />
<%=qGreeting.ToString() %>>
</prompt>
<goto next="#playQuestion" />
</block>
</form>
<form id="playQuestion">
<var name="datasource" expr="<%=myDoc;%>" />
<data name="domQuestion" srcexpr="datasource" />
<block>
<script>
function question(QuestionID, QuestionName, QuestionTypeID,
QuestionText, QuestionIsActive, OptionGroupID, QuestionTypeText,
QuestionActionId, QuestionActionText, QuestionSkipLogic,
QuestionCSSClass, QuestionOrder, QuestionIsRandom, QuestionRequired) {
this.QuestionID = QuestionID;
this.QuestionName = QuestionName;
this.QuestionTypeID = QuestionTypeID;
this.QuestionText = QuestionText;
this.QuestionIsActive = QuestionIsActive,
this.OptionGroupID = OptionGroupID;
this.QuestionTypeText = QuestionTypeText;
this.QuestionActionId = QuestionActionId;
this.QuestionActionText = QuestionActionText;
this.QuestionSkipLogic = QuestionSkipLogic;
this.QuestionCSSClass = QuestionCSSClass;
this.QuestionOrder = QuestionOrder;
this.QuestionIsRandom = QuestionIsRandom;
this.QuestionRequired = QuestionRequired;
};
var q = domQuestion.documentElement.getElementsByTagName("Question");
var qArray = [];
for (var i = 0; i = i.q.length; i++) {
var newQ = new question
(q.item(i).childNode[0].toString(),
q.item(i).childNode[1].toString(),
q.item(i).childNode[2].toString(),
q.item(i).childNode[3].toString(),
q.item(i).childNode[4].toString(),
q.item(i).childNode[5].toString(),
q.item(i).childNode[6].toString(),
q.item(i).childNode[7].toString(),
q.item(i).childNode[8].toString(),
q.item(i).childNode[9].toString(),
q.item(i).childNode[10].toString(),
q.item(i).childNode[11].toString(),
q.item(i).childNode[12].toString(),
q.item(i).childNode[13].toString()
);
qArray[i] = newQ;
}
</script>
<prompt>
<foreach item="question" array="qArray">
<value expr="question.QuestionText"></value>
</foreach>
</prompt>
</block>
</form>
</vxml>
Code: Select all
private XDocument _doc;
public XDocument myDoc { get { return _doc; } }
private Questionnaire qt;
public Questionnaire questionnaire { get { return qt; } }
public string callParam;
private string greeting;
public string qGreeting { get { return greeting; } }
protected void GetGreeting()
{
callParam = Request["callParams"];
int questID = Convert.ToInt32(callParam);
HttpClient client = new HttpClient();
string baseUrl = "http://XXX.XX.XXX.XX/PVTest/";
client.BaseAddress = new Uri(baseUrl);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
string serviceUrl;
serviceUrl = "api/Questionnaire/" + questID.ToString();
HttpResponseMessage response = client.GetAsync(serviceUrl).Result;
if (response.IsSuccessStatusCode)
{
Questionnaire quest = response.Content.ReadAsAsync<Questionnaire>().Result;
qt = quest;
greeting = quest.QuestionnaireGreeting.ToString();
XDocument doc = new XDocument(new XDeclaration("1.0", "utf-8", string.Empty),
new XElement("questions")
);
foreach (QuestionnaireQuestions q in qt.Questions)
{
doc.Root.Add(
new XElement("Question",
new XElement("QuestionID", q.QuestionID),
new XElement("QuestionName", q.QuestionName),
new XElement("QuestionTypeId", q.QuestionTypeId),
new XElement("QuestionText", q.QuestionText),
new XElement("QuestionIsActive", q.QuestionIsActive),
new XElement("OptionGroupID", q.OptionGroupID),
new XElement("QuestionTypeText", q.QuestionTypeText),
new XElement("QuestionActionId", q.QuestionActionId),
new XElement("QuestionActionText", q.QuestionActionId),
new XElement("QuestionSkipLogic", q.QuestionSkipLogic),
new XElement("QuestionCSSClass", q.QuestionCSSClass),
new XElement("QuestionOrder", q.QuestionOrder),
new XElement("QuestionIsRandom", q.QuestionIsRandom),
new XElement("QuestionRequired", q.QuestionRequired)
));
}
_doc = doc;
}
else
{
greeting = "No greeting.";
}
}
}