https://demo.docusign.net/restapi/v2.1/accounts/<DocuSignAccountID>/envelopes
https://demo.docusign.net/restapi/v2.1/accounts/<DocuSignAccountID>/envelopes/<EnvelopeID>/views/rec...
@app.route('/envelopes', methods=['POST']) #route expressed in the webhook configuration of the chatbot
def envelopes():
postRece = json.loads(request.get_data()) #getting data from the chatbot
conversationId = postRece['conversation']['id']
language = postRece['conversation']['language']
terminosPago = postRece['conversation']['memory']['terminospago']['raw']
#url for creating the envelope
url_1 = "https://demo.docusign.net/restapi/v2.1/accounts/<DocuSign Account ID>/envelopes"
#payload to create the envelope
payload_1 = {
"templateId": <templateID>,
"emailSubject": "BestRun Contract",
"status": "sent",
"templateRoles": [
{
"email": <email>,
"name": "John Smith",
"roleName": "Signer",
"tabs": {
"textTabs":[
{
"tabLabel": "fullName",
"value": "John Smith"
},
{
"tabLabel": "name",
"value": name
},
{
"tabLabel": "lastName1",
"value": "Smith"
},
{
"tabLabel": "lastName2",
"value": "Q"
},
{
"tabLabel": "street",
"value": "Marsella"
},
{
"tabLabel": "ext",
"value": "20"
},
{
"tabLabel": "int",
"value": "03"
},
{
"tabLabel": "colonia",
"value": "Juárez"
},
{
"tabLabel": "zipCode",
"value": "06600"
},
{
"tabLabel": "city",
"value": "Cuauhtémoc"
},
{
"tabLabel": "state",
"value": "CDMX"
},
{
"tabLabel": "conversationId",
"value": conversationId
},
{
"tabLabel": "terminosPago",
"value": terminosPago
},
{
"tabLabel": "email",
"value": <email>
}
]
}
}
]}
#headers to authenticate to the DocuSign account
headers = {
'X-DocuSign-Authentication': json.dumps({"Username": "<Docusign Demo Account Email>","Password": "<DocuSign Demo Account Password>","IntegratorKey": "<Integrator Key>"}),
'Content-Type': 'application/json'
}
#response of creating the envelope
response = requests.request("POST", url_1, headers= headers, data = json.dumps(payload_1))
print(response.text.encode('utf8'))
#url for viewing the recipient (to get the generated document url)
url_2 = "https://demo.docusign.net/restapi/v2.1/accounts/<DocuSign Account ID>/envelopes/{}/views/recipient".format(response.json()['envelopeId'])
#payload to "request" the generated document url
payload_2 = {
"authenticationMethod": "None",
"email": "<DocuSign Demo Account Email>",
"recipientId": "1",
"returnUrl": "https://www.sap.com/latinamerica/index.html", #change the return URL if you want
"userName": "<DocuSign Demo Account Email>"
}
response_2 = requests.request("POST", url_2, headers=headers, data = json.dumps(payload_2))
recipient_url = json.loads(response_2.text)['url']
#response to the chatbot, in this way the user will view the document in order to sign it
messageCAI = "Perfect, in order to continue with your purchase with a {}, it is required your e-signature in this contract, where you can find the Terms and Conditions of your loan application.".format(terminosPago)
return jsonify(
status=200,
replies=[{
'type': 'buttons',
'content': {
'title': messageCAI,
'buttons': [{
'value': recipient_url,
'title': 'Sign Here',
'type': 'web_url'
}]
}
}])
@app.route('/statusrecipient', methods=['POST'])
def statusrecipient():
webhook = request.get_data()
#DocuSign sends the XML file as a string. Needs to be convert to a XML object.
test_webhook = ET.fromstring(webhook)
#Using XPath to find values inside the XML object, as the chatbot's conversationId and payment method (terminosPago).
conversationId = test_webhook.findall(".//*[@name='conversationId']")[0][0].text
terminosPago = test_webhook.findall(".//*[@name='terminosPago']")[0][0].text
#Using SAP Conversational AI API to send a message
url_chatbot = "https://api.cai.tools.sap/connect/v1/conversations/{}/messages".format(conversationId)
payload = {
"messages": [
{
'type': 'text',
'delay': 2,
'content': 'Thank you very much, I have received your e-signature confirmation. At this moment I am creating your purchase order.'
},
{
'type': 'text',
'delay': 0,
'content': 'Your order number is: XXXXX. Thanks again for using our BestRun Digital Assistant.'
},
{
'type': 'card',
'delay': 0,
'content': {
'title': 'Would you like to rate our service?',
'subtitle':'Your opinion helps us to improve :)',
'imageUrl': 'https://i.imgur.com/qwIacDT.png',
'buttons': [
{
'title': 'Survey',
'value': 'https://qtrial2019q2az1.az1.qualtrics.com/jfe/form/SV_d7ssTuPIkOl4PCm', #You can create your own Qualtrics account to publish your surveys.
"type": 'web_url'
}
]
}
}
]}
response_3 = requests.post(url = url_chatbot, data = json.dumps(payload), headers = {"Authorization": "<Chatbot's Developer Token>", "Accept": "*/*", "Content-Type": "application/json"})
#returning the response to the chatbot
return jsonify(response = response_3.text)
cf push <app name> -f manifest.yml
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
10 | |
9 | |
7 | |
7 | |
7 | |
6 | |
6 | |
5 | |
4 |