def botlog_event(request): # Simulates a bot. telemetry = ApplicationInsightsTelemetryClient( None, common.create_client()) # Used shared client AppInsights uses. telemetry.track_event("botevent", { 'foo' : 'bar', 'moo' : 'cow'}) return HttpResponse("We logged a bot event")
# Clear out state await CONVERSATION_STATE.delete(context) # Set the error handler on the Adapter. # In this case, we want an unbound method, so MethodType is not needed. ADAPTER.on_turn_error = on_error # Create MemoryStorage, UserState and ConversationState MEMORY = MemoryStorage() USER_STATE = UserState(MEMORY) CONVERSATION_STATE = ConversationState(MEMORY) # Create telemetry client INSTRUMENTATION_KEY = app.config["APPINSIGHTS_INSTRUMENTATION_KEY"] TELEMETRY_CLIENT = ApplicationInsightsTelemetryClient(INSTRUMENTATION_KEY) # Create dialog and Bot DIALOG = MainDialog(app.config, telemetry_client=TELEMETRY_CLIENT) BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG, TELEMETRY_CLIENT) # Listen for incoming requests on /api/messages. @app.route("/api/messages", methods=["POST"]) def messages(): # Main bot message handler. if "application/json" in request.headers["Content-Type"]: body = request.json else: return Response(status=415)
from django.shortcuts import render from django.http import HttpResponse from rest_framework.views import APIView from django.views.decorators.csrf import csrf_exempt from .custom_session import CsrfExemptSessionAuthentication from rest_framework.authentication import SessionAuthentication, BasicAuthentication from botbuilder.applicationinsights import ApplicationInsightsTelemetryClient instrumentation_key = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' telemetry = ApplicationInsightsTelemetryClient(instrumentation_key) class MyView(APIView): authentication_classes = (CsrfExemptSessionAuthentication, BasicAuthentication) @csrf_exempt def post(self, request, *args, **kwargs): telemetry.track_event("DjangoHello") telemetry.flush() return HttpResponse("YOU POSTED DATA.")
# Create MemoryStorage, UserState and ConversationState MEMORY = MemoryStorage() USER_STATE = UserState(MEMORY) CONVERSATION_STATE = ConversationState(MEMORY) # Create adapter. # See https://aka.ms/about-bot-adapter to learn more about how bots work. ADAPTER = AdapterWithErrorHandler(SETTINGS, CONVERSATION_STATE) # Create telemetry client. # Note the small 'client_queue_size'. This is for demonstration purposes. Larger queue sizes # result in fewer calls to ApplicationInsights, improving bot performance at the expense of # less frequent updates. INSTRUMENTATION_KEY = CONFIG.APPINSIGHTS_INSTRUMENTATION_KEY TELEMETRY_CLIENT = ApplicationInsightsTelemetryClient( INSTRUMENTATION_KEY, telemetry_processor=AiohttpTelemetryProcessor(), client_queue_size=10) # Create dialogs and Bot RECOGNIZER = FlightBookingRecognizer(CONFIG) BOOKING_DIALOG = BookingDialog() DIALOG = MainDialog(RECOGNIZER, BOOKING_DIALOG, telemetry_client=TELEMETRY_CLIENT) BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG, TELEMETRY_CLIENT) # Listen for incoming requests on /api/messages. async def messages(req: Request) -> Response: # Main bot message handler.