8000 pylint and black, suggested corrections. · rusty0209/botbuilder-python@5e275f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e275f0

Browse files
author
Tracy Boehrer
committed
pylint and black, suggested corrections.
1 parent 2f89ffb commit 5e275f0

File tree

2 files changed

+58
-46
lines changed

2 files changed

+58
-46
lines changed

samples/23.facebook-events/app.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
import asyncio
55
import sys
66
from datetime import datetime
7-
from types import MethodType
87

98
from flask import Flask, request, Response
10-
from botbuilder.core import BotFrameworkAdapterSettings, TurnContext, BotFrameworkAdapter
9+
from botbuilder.core import (
10+
BotFrameworkAdapterSettings,
11+
TurnContext,
12+
BotFrameworkAdapter,
13+
)
1114
from botbuilder.schema import Activity, ActivityTypes
1215

1316
from bots import FacebookBot
@@ -32,21 +35,24 @@ async def on_error(context: TurnContext, error: Exception):
3235

3336
# Send a message to the user
3437
await context.send_activity("The bot encountered an error or bug.")
35-
await context.send_activity("To continue to run this bot, please fix the bot source code.")
38+
await context.send_activity(
39+
"To continue to run this bot, please fix the bot source code."
40+
)
3641
# Send a trace activity if we're talking to the Bot Framework Emulator
37-
if context.activity.channel_id == 'emulator':
42+
if context.activity.channel_id == "emulator":
3843
# Create a trace activity that contains the error object
3944
trace_activity = Activity(
4045
label="TurnError",
4146
name="on_turn_error Trace",
4247
timestamp=datetime.utcnow(),
4348
type=ActivityTypes.trace,
4449
value=f"{error}",
45-
value_type="https://www.botframework.com/schemas/error"
50+
value_type="https://www.botframework.com/schemas/error",
4651
)
4752
# Send a trace activity, which will be displayed in Bot Framework Emulator
4853
await context.send_activity(trace_activity)
4954

55+
5056
ADAPTER.on_turn_error = on_error
5157

5258
# Create the Bot

samples/23.facebook-events/bots/facebook_bot.py

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from botbuilder.core import ActivityHandler, MessageFactory, TurnContext, CardFactory
66
from botbuilder.schema import ChannelAccount, CardAction, ActionTypes, HeroCard
77

8-
FacebookPageIdOption = "Facebook Id"
9-
QuickRepliesOption = "Quick Replies"
10-
PostBackOption = "PostBack"
8+
FACEBOOK_PAGEID_OPTION = "Facebook Id"
9+
QUICK_REPLIES_OPTION = "Quick Replies"
10+
POSTBACK_OPTION = "PostBack"
1111

1212

1313
class FacebookBot(ActivityHandler):
@@ -19,7 +19,9 @@ async def on_members_added_activity(
1919
await turn_context.send_activity("Hello and welcome!")
2020

2121
async def on_message_activity(self, turn_context: TurnContext):
22-
if not await self._process_facebook_payload(turn_context, turn_context.activity.channel_data):
22+
if not await self._process_facebook_payload(
23+
turn_context, turn_context.activity.channel_data
24+
):
2325
await self._show_choices(turn_context)
2426

2527
async def on_event_activity(self, turn_context: TurnContext):
@@ -28,96 +30,100 @@ async def on_event_activity(self, turn_context: TurnContext):
2830
async def _show_choices(self, turn_context: TurnContext):
2931
choices = [
3032
Choice(
31-
value=QuickRepliesOption,
33+
value=QUICK_REPLIES_OPTION,
3234
action=CardAction(
33-
title=QuickRepliesOption,
35+
title=QUICK_REPLIES_OPTION,
3436
type=ActionTypes.post_back,
35-
value=QuickRepliesOption
36-
)
37+
value=QUICK_REPLIES_OPTION,
38+
),
3739
),
3840
Choice(
39-
value=FacebookPageIdOption,
41+
value=FACEBOOK_PAGEID_OPTION,
4042
action=CardAction(
41-
title=FacebookPageIdOption,
43+
title=FACEBOOK_PAGEID_OPTION,
4244
type=ActionTypes.post_back,
43-
value=FacebookPageIdOption
44-
)
45+
value=FACEBOOK_PAGEID_OPTION,
46+
),
4547
),
4648
Choice(
47-
value=PostBackOption,
49+
value=POSTBACK_OPTION,
4850
action=CardAction(
49-
title=PostBackOption,
51+
title=POSTBACK_OPTION,
5052
type=ActionTypes.post_back,
51-
value=PostBackOption
52-
)
53-
)
53+
value=POSTBACK_OPTION,
54+
),
55+
),
5456
]
5557

5658
message = ChoiceFactory.for_channel(
5759
turn_context.activity.channel_id,
5860
choices,
59-
"What Facebook feature would you like to try? Here are some quick replies to choose from!"
61+
"What Facebook feature would you like to try? Here are some quick replies to choose from!",
6062
)
6163
await turn_context.send_activity(message)
6264

6365
async def _process_facebook_payload(self, turn_context: TurnContext, data) -> bool:
6466
if "postback" in data:
6567
await self._on_facebook_postback(turn_context, data["postback"])
6668
return True
67-
elif "optin" in data:
69+
70+
if "optin" in data:
6871
await self._on_facebook_optin(turn_context, data["optin"])
6972
return True
70-
elif "message" in data and "quick_reply" in data["message"]:
71-
await self._on_facebook_quick_reply(turn_context, data["message"]["quick_reply"])
73+
74+
if "message" in data and "quick_reply" in data["message"]:
75+
await self._on_facebook_quick_reply(
76+
turn_context, data["message"]["quick_reply"]
77+
)
7278
return True
73-
elif "message" in data and data["message"]["is_echo"]:
79+
80+
if "message" in data and data["message"]["is_echo"]:
7481
await self._on_facebook_echo(turn_context, data["message"])
7582
return True
7683

77-
async def _on_facebook_postback(self, turn_context: TurnContext, facebook_postback: dict):
84+
async def _on_facebook_postback(
85+
self, turn_context: TurnContext, facebook_postback: dict
86+
):
7887
# TODO: Your PostBack handling logic here...
7988

80-
reply = MessageFactory.text("Postback")
89+
reply = MessageFactory.text(f"Postback: {facebook_postback}")
8190
await turn_context.send_activity(reply)
8291
await self._show_choices(turn_context)
8392

84-
async def _on_facebook_quick_reply(self, turn_context: TurnContext, facebook_quick_reply: dict):
93+
async def _on_facebook_quick_reply(
94+
self, turn_context: TurnContext, facebook_quick_reply: dict
95+
):
8596
# TODO: Your quick reply event handling logic here...
8697

87-
if turn_context.activity.text == FacebookPageIdOption:
98+
if turn_context.activity.text == FACEBOOK_PAGEID_OPTION:
8899
reply = MessageFactory.text(
89100
f"This message comes from the following Facebook Page: {turn_context.activity.recipient.id}"
90101
)
91102
await turn_context.send_activity(reply)
92103
await self._show_choices(turn_context)
93-
elif turn_context.activity.text == PostBackOption:
104+
elif turn_context.activity.text == POSTBACK_OPTION:
94105
card = HeroCard(
95106
text="Is 42 the answer to the ultimate question of Life, the Universe, and Everything?",
96107
buttons=[
97-
CardAction(
98-
title="Yes",
99-
type=ActionTypes.post_back,
100-
value="Yes"
101-
),
102-
CardAction(
103-
title="No",
104-
type=ActionTypes.post_back,
105-
value="No"
106-
)
107-
]
108+
CardAction(title="Yes", type=ActionTypes.post_back, value="Yes"),
109+
CardAction(title="No", type=ActionTypes.post_back, value="No"),
110+
],
108111
)
109112
reply = MessageFactory.attachment(CardFactory.hero_card(card))
110113
await turn_context.send_activity(reply)
111114
else:
115+
print(facebook_quick_reply)
112116
await turn_context.send_activity("Quick Reply")
113117
await self._show_choices(turn_context)
114118

115119
async def _on_facebook_optin(self, turn_context: TurnContext, facebook_optin: dict):
116120
# TODO: Your optin event handling logic here...
121+
print(facebook_optin)
117122
await turn_context.send_activity("Opt In")
118-
pass
119123

120-
async def _on_facebook_echo(self, turn_context: TurnContext, facebook_message: dict):
124+
async def _on_facebook_echo(
125+
self, turn_context: TurnContext, facebook_message: dict
126+
):
121127
# TODO: Your echo event handling logic here...
128+
print(facebook_message)
122129
await turn_context.send_activity("Echo")
123-
pass

0 commit comments

Comments
 (0)
0