8000 Merge branch 'master' into jj/echo-aiohttp · TheCompuGuru/botbuilder-python@c10d313 · GitHub
[go: up one dir, main page]

Skip to content

Commit c10d313

Browse files
authored
Merge branch 'master' into jj/echo-aiohttp
2 parents 6497ac8 + 68b7e21 commit c10d313

31 files changed

+393
-804
lines changed

.coveragerc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ source = ./libraries/
33
omit =
44
*/tests/*
55
setup.py
6-
*/botbuilder-schema/*
6+
*/botbuilder-schema/*
7+
*/functional-tests/*

azure-pipelines.yml

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,32 @@
1-
trigger:
1+
schedules:
2+
- cron: "0 0 * * *"
3+
displayName: Daily midnight build
24
branches:
35
include:
4-
- daveta-python-functional
5-
exclude:
66
- master
77

88
variables:
9-
# Container registry service connection established during pipeline creation
10-
dockerRegistryServiceConnection: 'NightlyE2E-Acr'
11-
azureRmServiceConnection: 'NightlyE2E-RM'
12-
dockerFilePath: 'libraries/functional-tests/functionaltestbot/Dockerfile'
13-
buildIdTag: $(Build.BuildNumber)
14-
webAppName: 'e2epython'
15-
containerRegistry: 'nightlye2etest.azurecr.io'
16-
imageRepository: 'functionaltestpy'
17-
18-
19-
9+
resourceGroupName: 'pyfuntest'
2010

2111
jobs:
22-
# Build and publish container
23-
- job: Build
12+
- job: Doit
2413
pool:
2514
vmImage: 'Ubuntu-16.04'
26-
displayName: Build and push bot image
27-
continueOnError: false
28-
steps:
29-
- task: Docker@2
30-
displayName: Build and push bot image
31-
inputs:
32-
command: buildAndPush
33-
repository: $(imageRepository)
34-
dockerfile: $(dockerFilePath)
35-
containerRegistry: $(dockerRegistryServiceConnection)
36-
tags: $(buildIdTag)
37-
3815

39-
40-
- job: Deploy
41-
displayName: Provision bot container
42-
pool:
43-
vmImage: 'Ubuntu-16.04'
44-
dependsOn:
45-
- Build
4616
steps:
47-
- task: AzureRMWebAppDeployment@4
48-
displayName: Python Functional E2E test.
17+
- task: UsePythonVersion@0
18+
displayName: Use Python 3.6
4919
inputs:
50-
ConnectionType: AzureRM
51-
ConnectedServiceName: $(azureRmServiceConnection)
52-
appType: webAppContainer
53-
WebAppName: $(webAppName)
54-
DockerNamespace: $(containerRegistry)
55-
DockerRepository: $(imageRepository)
56-
DockerImageTag: $(buildIdTag)
57-
AppSettings: '-MicrosoftAppId $(botAppId) -MicrosoftAppPassword $(botAppPassword) -FLASK_APP /functionaltestbot/app.py -FLASK_DEBUG 1'
58-
59-
#StartupCommand: 'flask run --host=0.0.0.0 --port=3978'
60-
20+
versionSpec: '3.6'
6121

22+
- task: AzureCLI@2
23+
displayName: Provision, Deploy and run tests
24+
inputs:
25+
azureSubscription: 'FUSE Temporary (174c5021-8109-4087-a3e2-a1de20420569)'
26+
scriptType: 'bash'
27+
scriptLocation: 'inlineScript'
28+
inlineScript: |
29+
cd $(Build.SourcesDirectory)/libraries/functional-tests/functionaltestbot
30+
chmod +x ./scripts/deploy_webapp.sh
31+
./scripts/deploy_webapp.sh --appid $(botAppId) --password $(botAppPassword) -g $(resourceGroupName)
32+
continueOnError: false

libraries/functional-tests/functionaltestbot/Dockerfile

Lines changed: 0 additions & 48 deletions
This file was deleted.

libraries/functional-tests/functionaltestbot/Dockfile

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Functional Test Bot
2+
This bot is the "Echo" bot which perform E2E functional test.
3+
- Cleans up
4+
- Deploys the python echo bot to Azure
5+
- Creates an Azure Bot and associates with the deployed python bot.
6+
- Creates a DirectLine channel and associates with the newly created bot.
7+
- Runs a client test, using the DirectLine channel and and verifies response.
8+
9+
This is modeled in a Devops.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import asyncio
5+
import sys
6+
import os
7+
from datetime import datetime
8+
9+
from flask import Flask, request, Response
10+
from botbuilder.core import (
11+
BotFrameworkAdapterSettings,
12+
BotFrameworkAdapter,
13+
TurnContext,
14+
)
15+
from botbuilder.schema import Activity, ActivityTypes
16+
17+
from bots import EchoBot
18+
19+
# Create the loop and Flask app
20+
LOOP = asyncio.get_event_loop()
21+
# pylint: disable=invalid-name
22+
app = Flask(__name__, instance_relative_config=True)
23+
app.config.from_object("config.DefaultConfig")
24+
25+
# Create adapter.
26+
# See https://aka.ms/about-bot-adapter to learn more about how bots work.
27+
SETTINGS = BotFrameworkAdapterSettings(
28+
os.environ.get("MicrosoftAppId", ""), os.environ.get("MicrosoftAppPassword", "")
29+
)
30+
ADAPTER = BotFrameworkAdapter(SETTINGS)
31+
32+
33+
# Catch-all for errors.
34+
async def on_error(context: TurnContext, error: Exception):
35+
# This check writes out errors to console log .vs. app insights.
36+
# NOTE: In production environment, you should consider logging this to Azure
37+
# application insights.
38+
print(f"\n [on_turn_error] unhandled error: {error}", file=sys.stderr)
39+
40+
# Send a message to the user
41+
await context.send_activity("The bot encountered an error or bug.")
42+
await context.send_activity(
43+
"To continue to run this bot, please fix the bot source code."
44+
)
45+
# Send a trace activity if we're talking to the Bot Framework Emulator
46+
if context.activity.channel_id == "emulator":
47+
# Create a trace activity that contains the error object
48+
trace_activity = Activity(
49+
label="TurnError",
50+
name="on_turn_error Trace",
51+
timestamp=datetime.utcnow(),
52+
type=ActivityTypes.trace,
53+
value=f"{error}",
54+
value_type="https://www.botframework.com/schemas/error",
55+
)
56+
# Send a trace activity, which will be displayed in Bot Framework Emulator
57+
await context.send_activity(trace_activity)
58+
59+
60+
ADAPTER.on_turn_error = on_error
61+
62+
# Create the Bot
63+
BOT = EchoBot()
64+
65+
# Listen for incoming requests on /api/messages
66+
@app.route("/api/messages", methods=["POST"])
67+
def messages():
68+
# Main bot message handler.
69+
if "application/json" in request.headers["Content-Type"]:
70+
body = request.json
71+
else:
72+
return Response(status=415)
73+
74+
activity = Activity().deserialize(body)
75+
auth_header = (
76+
request.headers["Authorization"] if "Authorization" in request.headers else ""
77+
)
78+
79+
try:
80+
task = LOOP.create_task(
81+
ADAPTER.process_activity(activity, auth_header, BOT.on_turn)
82+
)
83+
LOOP.run_until_complete(task)
84+
return Response(status=201)
85+
except Exception as exception:
86+
raise exception
87+
88+
89+
@app.route("/", methods=["GET"])
90+
def ping():
91+
return "Hello World!"
92+
93+
94+
if __name__ == "__main__":
95+
try:
96+
app.run(debug=False, port=3978) # nosec debug
97+
except Exception as exception:
98+
raise exception
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4-
from .app import APP
4+
from .echo_bot import EchoBot
55

6-
__all__ = ["APP"]
6+
__all__ = ["EchoBot"]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
from botbuilder.core import ActivityHandler, MessageFactory, TurnContext
5+
from botbuilder.schema import ChannelAccount
6+
7+
8+
class EchoBot(ActivityHandler):
9+
async def on_members_added_activity(
10+
self, members_added: [ChannelAccount], turn_context: TurnContext
11+
):
12+
for member in members_added:
13+
if member.id != turn_context.activity.recipient.id:
14+
await turn_context.send_activity("Hello and welcome!")
15+
16+
async def on_message_activity(self, turn_context: TurnContext):
17+
return await turn_context.send_activity(
18+
MessageFactory.text(f"Echo: {turn_context.activity.text}")
19+
)

libraries/functional-tests/functionaltestbot/client_driver/README.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

libraries/functional-tests/functionaltestbot/functionaltestbot/config.py renamed to libraries/functional-tests/functionaltestbot/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
class DefaultConfig:
99
""" Bot Configuration """
1010

11-
PORT = 443
11+
PORT = 3978
1212
APP_ID = os.environ.get("MicrosoftAppId", "")
1313
APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "")

libraries/functional-tests/functionaltestbot/flask_bot_app/app.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0