Advertisement
Guest User

Untitled

a guest
Sep 30th, 2019
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. from django.shortcuts import render
  2. from django.http import HttpResponse, JsonResponse
  3. from django.views.decorators.csrf import csrf_exempt
  4. from library.df_response_lib import *
  5. import json
  6.  
  7. #define home function
  8. def home(request):
  9.     return HttpResponse('Hello World!')
  10.  
  11. @csrf_exempt
  12. def webhook(request):
  13.     # build a request object
  14.     req = json.loads(request.body)
  15.  
  16.     # get action from json
  17.     action = req.get('queryResult').get('action')
  18.     # prepare response for suggestions chips
  19.     if action == 'get_suggestions_chips':
  20.         #set fulfillment text
  21.         fulfillmentText = 'Suggestion chips response from webhook'
  22.         aog = actions_on_google_response()
  23.         aog_sr = aog.simple_response([[fulfillmentText, fulfillmentText, False]])
  24.         #create suggestion chips
  25.         aog_sc      = aog.suggestion_chips(["suggestion1", "suggestion2"])
  26.         ff_response = fulfillment_response()
  27.         ff_text     = ff_response.fulfillment_text(fulfillmentText)
  28.         ff_messages = ff_response.fulfillment_messages([aog_sr, aog_sc])
  29.         reply       = ff_response.main_response(ff_text, ff_messages)
  30.     # return response
  31.     return JsonResponse(reply, safe=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement