def create_wishlist_card(self, books: List): card = HeroCard(title="La tua wishlist") attachments = [] attachments.append(CardFactory.hero_card(card)) text = "" flag = False for book in books: flag = True if book.author is not None: text += "{} di {}\n\n".format(book.name, book.author) else: text += "{}\n\n".format(book.name) text += "Genere: {}\n".format(book.genre) text += "Nome del sito: {} \n".format(book.site) if book.price is not None: text += "Prezzo: {}€ \n".format(book.price) else: text += "Prezzo non disponibile.\n" text += "Disponibilità: {} \n".format(book.availability) text += "Link per l'acquisto: {} \n".format(book.link) attachments.append(CardFactory.hero_card(HeroCard(text=text))) text = "" if flag: activity = MessageFactory.carousel(attachments) return (activity, True) else: new_card = HeroCard( title="La tua wishlist è vuota", subtitle= '''Non puoi eseguire nessuna operazione. Puoi cercare un libro ed aggiungerlo. Ti riporto al menù principale. ''' ) attachments.append(CardFactory.hero_card(new_card)) activity = MessageFactory.carousel(attachments) return (activity, False)
def test_should_return_a_carousel(self): activity = MessageFactory.carousel( [Attachment(content_type='a'), Attachment(content_type='b')]) assert_message(activity) assert_attachments(activity, 2, ['a', 'b']) assert activity.attachment_layout == AttachmentLayoutTypes.carousel, 'invalid attachment_layout.'
def test_should_return_a_carousel(self): activity = MessageFactory.carousel( [Attachment(content_type="a"), Attachment(content_type="b")]) assert_message(activity) assert_attachments(activity, 2, ["a", "b"]) assert (activity.attachment_layout == AttachmentLayoutTypes.carousel ), "invalid attachment_layout."
async def _send_carousel_card(self, turn_context: TurnContext): card_path = os.path.join(os.getcwd(), "cards\\hero_card.json") with open(card_path, "rb") as in_file: card_data = json.load(in_file) attachment = Attachment( content_type=CardFactory.content_types.hero_card, content=card_data) await turn_context.send_activity( MessageFactory.carousel([attachment, attachment, attachment]))
def test_should_return_a_carousel_with_text_speak_and_input_hint(self): activity = MessageFactory.carousel( [Attachment(content_type='a'), Attachment(content_type='b')], 'test1', 'test2', InputHints.ignoring_input) assert_message(activity) assert_attachments(activity, 2, ['a', 'b']) assert activity.attachment_layout == AttachmentLayoutTypes.carousel, 'invalid attachment_layout.' assert activity.text == 'test1', 'invalid text field.' assert activity.speak == 'test2', 'invalid speak field.' assert activity.input_hint == InputHints.ignoring_input, 'invalid input_hint field.'
def test_should_return_a_carousel_with_text_speak_and_input_hint(self): activity = MessageFactory.carousel( [Attachment(content_type="a"), Attachment(content_type="b")], "test1", "test2", InputHints.ignoring_input, ) assert_message(activity) assert_attachments(activity, 2, ["a", "b"]) assert (activity.attachment_layout == AttachmentLayoutTypes.carousel ), "invalid attachment_layout." assert activity.text == "test1", "invalid text field." assert activity.speak == "test2", "invalid speak field." assert (activity.input_hint == InputHints.ignoring_input ), "invalid input_hint field."
def create_card(books, categoria): card = HeroCard( title="Ecco i miei suggerimenti per te per la categoria: {}". format(categoria)) attachments = [] attachments.append(CardFactory.hero_card(card)) text = "" for book in books: text += "Titolo: {}\n".format(book.name) text += "Nome del sito: Amazon\n" if book.price is not None: text += "Prezzo: {}€ \n".format(book.price) else: text += "Prezzo non disponibile.\n" text += "Link per l'acquisto: {} \n".format(book.link) attachments.append(CardFactory.hero_card(HeroCard(text=text))) text = "" activity = MessageFactory.carousel(attachments) return activity
def create_result_card(self, books): title = None author = None genre = None for book in books: if book.name is not None: title = book.name break for book in books: if book.author is not None: author = book.author break for book in books: if book.genre is not None: genre = book.genre break attachments = [] if title is not None and author is not None and genre is not None: subtitle = "{} di {} \nGenere: {}".format(title, author, genre) card = HeroCard(title="RISULTATI", subtitle=subtitle) attachments.append(CardFactory.hero_card(card)) text = "" for book in books: text += "Nome del sito: {} \n".format(book.site) if book.price is not None: text += "Prezzo: {}€ \n".format(book.price) else: text += "Prezzo non disponibile.\n" text += "Disponibilità: {} \n".format(book.availability) text += "Link per l'acquisto: {} \n".format(book.link) attachments.append(CardFactory.hero_card(HeroCard(text=text))) text = "" else: text = "Errore durante la ricerca del libro" attachments.append(CardFactory.hero_card(HeroCard(text=text))) return MessageFactory.carousel(attachments)
async def on_message_activity(self, turn_context: TurnContext): turn_context.activity.address = '' ## DB insert old user id_res = self.db_func.DB_query('SELECT ID FROM user_info') user_id = turn_context.activity.recipient.id # if userid not in our db, add it if user_id not in id_res: insert_query = 'INSERT INTO user_info (ID, counter) VALUES (\'' + user_id + '\', 0);' self.db_func.DB_insert(insert_query) self.db_func.DB_commit() ## QnA Maker's response response = await self.qna_maker.get_answers(turn_context) #check_list = await self.qna_maker.get_questions(turn_context) ## LUIS's result & intent recognizer_result = await self.recognizer.recognize(turn_context) # parse intent and entity intent = LuisRecognizer.top_intent(recognizer_result) print(intent) ## get user input and make response luis_result = recognizer_result.properties["luisResult"] entity = '' # check if user typing in qna maker if response and len(response) > 0 and (turn_context.activity.text != response[0].answer): await turn_context.send_activity( MessageFactory.text(response[0].answer)) # 個人化推薦 elif turn_context.activity.text == '個人化推薦': todayrecom = todaytop3eat() await turn_context.send_activity("今天最低溫為 %s, 為您推薦以下料理:" % todayrecom[0]) todaylist = [] for tt in range(3): restaurants_dict = googlemaps_API("北車", 3, todayrecom[1][tt]) todaylist.append( CardFactory.hero_card( HeroCard( title=restaurants_dict[0]['name'], text='推薦指數 : ' + str(restaurants_dict[0]['rating']), images=[ CardImage(url=show_photo(restaurants_dict[0] ['photo_reference'])) ], buttons=[ CardAction( type="openUrl", title="地圖", value= "https://www.google.com/maps/search/?api=1&query=" + str(restaurants_dict[0]['location_x']) + "," + str(restaurants_dict[0]['location_y']) + "&query_place_id=" + str(restaurants_dict[0]['place_id'])), CardAction(type="imBack", title="點此看評論", value=restaurants_dict[0]['name'] + "_評論"), CardAction(type="imBack", title="加入我的最愛", value=restaurants_dict[0]['name'] + "_加入最愛") ]))) msg = MessageFactory.carousel(todaylist) await turn_context.send_activity(msg) elif "加入最愛" in turn_context.activity.text: ## add favorite button rest_name = turn_context.activity.text.split("_")[0] message = self.favor.add_favorite(user_id, rest_name) await turn_context.send_activity(message) elif turn_context.activity.text == '瀏覽紀錄': res = self.history.get_history(user_id) if (res == []): await turn_context.send_activity("還沒有瀏覽紀錄,趕快搜尋餐廳吧~GOGO") else: history_list = [] for length in range(len(res)): rest_name = res[length] rest_location = find_position_with_xy(rest_name) (x, y) = googlemaps_search_location(rest_name) history_list.append( CardFactory.hero_card( HeroCard( title=rest_name, subtitle=rest_location, buttons=[ CardAction( type="openUrl", title="地圖", value= "https://www.google.com/maps/search/?api=1&query=" + str(x) + ',' + str(y)) ]))) message = MessageFactory.carousel(history_list) await turn_context.send_activity(message) elif turn_context.activity.text == '我的最愛': res = self.favor.get_favorite(user_id) if (res == []): await turn_context.send_activity("還沒有最愛的餐廳,趕快搜尋餐廳並加入最愛吧~GOGO") else: fav_list = [] for length in range(len(res)): rest_name = res[length] rest_location = find_position_with_xy(rest_name) (x, y) = googlemaps_search_location(rest_name) fav_list.append( CardFactory.hero_card( HeroCard( title=rest_name, subtitle=rest_location, buttons=[ CardAction( type="openUrl", title="地圖", value= "https://www.google.com/maps/search/?api=1&query=" + str(x) + ',' + str(y)) ]))) message = MessageFactory.carousel(fav_list) await turn_context.send_activity(message) elif "加入最愛" in turn_context.activity.text: ## add favorite button rest_name = turn_context.activity.text.split("_")[0] message = self.favor.add_favorite(user_id, rest_name) await turn_context.send_activity(message) # 歷史紀錄 elif turn_context.activity.text == '瀏覽紀錄': res = self.history.get_history(user_id) print(user_id) if (res is None): await turn_context.send_activity("還沒有瀏覽紀錄,趕快搜尋餐廳吧~") else: history_list = [] for length in range(len(res)): rest_name = res[length] rest_location = find_position_with_xy(rest_name) history_list.append( CardFactory.hero_card( HeroCard(title=rest_name, subtitle=rest_location))) message = MessageFactory.carousel(history_list) await turn_context.send_activity(message) # IG elif "_IG" in turn_context.activity.text: hashtag = turn_context.activity.text.split("_")[0].split( ' ')[0].split('-')[0].split('/')[0].split("'")[0].split('&')[0] url = "https://www.instagram.com/explore/tags/" + str(hashtag) # print(url) await turn_context.send_activity("稍等一下唷! 美食公道伯正在幫你尋找餐廳的IG熱門貼文...") asa = [] asa.append( CardFactory.hero_card( HeroCard( title=hashtag + '的IG熱門文章', images=[ CardImage( url= 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQB1DfQKJ-vfC16ybbNPP0N7FVVV6bNEC3W9Q&usqp=CAU' ) ], buttons=[ CardAction(type="openUrl", title="前往IG熱門文章", value=str(url)) ]))) message = MessageFactory.carousel(asa) await turn_context.send_activity(message) # 找評論 elif "評論" in turn_context.activity.text: await turn_context.send_activity("稍等一下唷! 美食公道伯正在幫你尋找餐廳評論...") # 展宏的func re = webcrawl(turn_context.activity.text) # 佑誠的func blog_re = [] blog_re = blogcrawler(turn_context.activity.text) review_list = [] for index in range(len(blog_re)): url = str(blog_re[index][2]) review_list.append( CardFactory.hero_card( HeroCard(title=blog_re[index][1], images=[CardImage(url=blog_re[index][3])], buttons=[ CardAction(type="openUrl", title="前往網頁", value=str(url)) ]))) if re: url = str(re["愛食記"][1]) review_list.append( CardFactory.hero_card( HeroCard(title=re["愛食記"][0], images=[CardImage(url=re["愛食記"][2])], buttons=[ CardAction(type="openUrl", title="前往網頁", value=str(url)) ]))) if len(review_list) != 0: message = MessageFactory.carousel(review_list) else: message = "未查詢到這間餐廳的相關評論文章喔~ 歡迎您發布首則評論!" rest_name = turn_context.activity.text.split("_")[0] self.history.add_history(user_id, rest_name) message = MessageFactory.carousel(review_list) await turn_context.send_activity(message) # 書文的func # line address elif ("{" in turn_context.activity.text and "}" in turn_context.activity.text): line_address_json = json.loads(turn_context.activity.text) print('line_address_json', line_address_json) x = line_address_json['latitude'] y = line_address_json['longitude'] restaurants_dict = googlemaps_search_nearby(x, y, 'steak') # 沒有餐廳的狀況 if (len(restaurants_dict) == 0): message = "您附近沒有相對應的餐廳可以推薦呦,輸入『吃』來繼續👀" else: restaurants_list = [] for i in range(len(restaurants_dict)): restaurants_list.append( CardFactory.hero_card( HeroCard( title=restaurants_dict[i]['name'], text='推薦指數 : ' + str(restaurants_dict[i]['rating']) + "👍", images=[ CardImage( url=show_photo(restaurants_dict[i] ['photo_reference'])) ], buttons=[ CardAction( type="openUrl", title="地圖", value= "https://www.google.com/maps/search/?api=1&query=" + str(restaurants_dict[i]['location_x']) + "," + str(restaurants_dict[i]['location_y']) + "&query_place_id=" + str(restaurants_dict[i]['place_id'])), CardAction( type="imBack", title="點此看IG熱門貼文", value=restaurants_dict[i]['name'] + "_IG"), CardAction( type="imBack", title="點此看評論", value=restaurants_dict[i]['name'] + "_評論"), CardAction( type="imBack", title="加入我的最愛", value=restaurants_dict[i]['name'] + "_加入最愛") ]))) if (i == 9): break message = MessageFactory.carousel(restaurants_list) await turn_context.send_activity(message) #如果推薦給使用者的都不喜歡吃 就隨機推薦 elif turn_context.activity.text == '都不喜歡': recom_list = [ '鍋貼', '牛排', '燒烤', '水餃', '飯', '拉麵', '鐵板燒', '炸物', '壽喜燒', '吃到飽' ] #res = [random.randrange(0, 9, 1) for i in range(3)] res = random.sample(range(10), 3) #產生不重複的 #print("result:", list2) message = MessageFactory.carousel([ CardFactory.hero_card( HeroCard(subtitle='請選擇您想吃的類型: 😗', buttons=[ CardAction(type="imBack", title=recom_list[res[0]], value="我想吃" + recom_list[res[0]]), CardAction(type="imBack", title=recom_list[res[1]], value="我想吃" + recom_list[res[1]]), CardAction(type="imBack", title=recom_list[res[2]], value="我想吃" + recom_list[res[2]]), CardAction(type="imBack", title="都不喜歡 😡", value="都不喜歡") ])) ]) await turn_context.send_activity(message) else: ## LUIS's result & intent recognizer_result = await self.recognizer.recognize(turn_context) # parse intent and entity intent = LuisRecognizer.top_intent(recognizer_result) print(intent) ## get user input and make response luis_result = recognizer_result.properties["luisResult"] entity = '' if luis_result.entities: entities_list = [] for ll in luis_result.entities: print(turn_context.activity.text) print(ll) ll.entity = ll.entity.replace(" ", '') entities_list.append(ll.entity) print(entities_list) print(len(entities_list)) if len(entities_list) == 1: entity = entities_list[0] # two entites situation else: entity = entities_list[0] + '^' + entities_list[1] print("double entity:", entity) entity = entity.replace("\x08", '') if intent == "使用者食物類別" and "_$" not in turn_context.activity.text and "_IG" not in turn_context.activity.text: message = MessageFactory.carousel([ CardFactory.hero_card( HeroCard( title='您想吃的食物為:' + str(entity), subtitle='請選擇您的預算區間: 🤑', buttons=[ CardAction(type="imBack", title="$$$", value="我想吃" + str(entity) + "_$$$"), CardAction(type="imBack", title="$$", value="我想吃" + str(entity) + "_$$"), CardAction(type="imBack", title="$", value="我想吃" + str(entity) + "_$") ])) ]) await turn_context.send_activity(message) # msg = '請輸入您目前的地點或是附近的景點 🧐(例如:北車、公館)(小提示:點擊Line的+號可以傳地址上來呦!)' # await turn_context.send_activity(msg) elif intent == "使用者地理位置" and "_$" not in turn_context.activity.text and "_IG" not in turn_context.activity.text: if entity == "": entity = turn_context.activity.text print(entity) message = MessageFactory.carousel([ CardFactory.hero_card( HeroCard( title='您的所在位置為:' + str(entity), subtitle='請選擇您的預算區間: 🤑', buttons=[ CardAction(type="imBack", title="$$$", value="我在" + str(entity) + "_$$$"), CardAction(type="imBack", title="$$", value="我在" + str(entity) + "_$$"), CardAction(type="imBack", title="$", value="我在" + str(entity) + "_$") ])) ]) await turn_context.send_activity(message) # find 2 entites in sequence elif "^" in entity: entity = entity.split("^") food = entity[0] location = entity[1] restaurants_dict = googlemaps_API(location, 2, food) # 沒有餐廳的狀況 if (len(restaurants_dict) == 0): message = "您附近沒有相對應的餐廳可以推薦呦,輸入『我想吃...』來繼續👀" else: restaurants_list = [] for i in range(len(restaurants_dict)): restaurants_list.append( CardFactory.hero_card( HeroCard( title=restaurants_dict[i]['name'], text='推薦指數 : ' + str(restaurants_dict[i]['rating']) + "👍", images=[ CardImage(url=show_photo( restaurants_dict[i] ['photo_reference'])) ], buttons=[ CardAction( type="openUrl", title="地圖", value= "https://www.google.com/maps/search/?api=1&query=" + str(restaurants_dict[i] ['location_x']) + "," + str(restaurants_dict[i] ['location_y']) + "&query_place_id=" + str(restaurants_dict[i] ['place_id'])), CardAction( type="imBack", title="點此看IG熱門貼文", value=restaurants_dict[i]['name'] + "_IG"), CardAction( type="imBack", title="點此看評論", value=restaurants_dict[i]['name'] + "_評論"), CardAction( type="imBack", title="加入我的最愛", value=restaurants_dict[i]['name'] + "_加入最愛") ]))) if (i == 9): break message = MessageFactory.carousel(restaurants_list) await turn_context.send_activity(message) elif ('_$' in turn_context.activity.text): money_status = 1 msg = turn_context.activity.text # 判斷price_level if ('_$$' in turn_context.activity.text): money_status = 2 msg = msg.replace('_$$', '') elif ('_$$$' in turn_context.activity.text): money_status = 3 msg = msg.replace('_$$$', '') msg = msg.replace('_$', '') msg = msg.replace('_', '') msg = msg.replace('我想吃', '') msg = msg.replace('我想喝', '') msg = msg.replace('我要吃', '') msg = msg.replace('我要喝', '') msg = msg.replace('我在', '') if (intent == '使用者食物類別'): restaurants_dict = googlemaps_API("北車", money_status, msg) print(restaurants_dict) elif (intent == '使用者地理位置'): restaurants_dict = googlemaps_API(msg, money_status, '') print(restaurants_dict) print('money_status:', money_status) print('msg:', msg) # 沒有餐廳的狀況 if not restaurants_dict: message = "您附近沒有相對應的餐廳可以推薦呦,輸入『我想吃...』來繼續👀" await turn_context.send_activity(message) else: # good_list = opendata_earth.get_earth_data() # vegetable_list = opendata_vegetable.get_vege_data() restaurants_list = [] for i in range(len(restaurants_dict)): restaurants_list.append( CardFactory.hero_card( HeroCard( title=restaurants_dict[i]['name'], text='推薦指數 : ' + str(restaurants_dict[i]['rating']) + " 👍", images=[ CardImage(url=show_photo( restaurants_dict[i] ['photo_reference'])) ], buttons=[ CardAction( type="openUrl", title="地圖", value= "https://www.google.com/maps/search/?api=1&query=" + str(restaurants_dict[i] ['location_x']) + "," + str(restaurants_dict[i] ['location_y']) + "&query_place_id=" + str(restaurants_dict[i] ['place_id'])), CardAction( type="imBack", title="點此看IG熱門貼文", value=restaurants_dict[i]['name'] + "_IG"), CardAction( type="imBack", title="點此看評論", value=restaurants_dict[i]['name'] + "_評論"), CardAction( type="imBack", title="加入我的最愛", value=restaurants_dict[i]['name'] + "_加入最愛") ]))) if (i == 9): break message = MessageFactory.carousel(restaurants_list) await turn_context.send_activity(message) elif turn_context.activity.address != '': turn_context.send_activity(turn_context.activity.address) # non-type else: message = MessageFactory.carousel([ CardFactory.hero_card( HeroCard(title="無法了解您的需求,美食公道伯在這邊先推薦幾家給您😉", subtitle='請選擇您想吃的類型: 😗', buttons=[ CardAction(type="imBack", title="咖啡廳", value="我想吃咖啡廳"), CardAction(type="imBack", title="牛排", value="我想吃牛排"), CardAction(type="imBack", title="火鍋", value="我想吃火鍋"), CardAction(type="imBack", title="都不喜歡 😡", value="都不喜歡") ])) ]) await turn_context.send_activity(message)
async def process_step( self, step_context: WaterfallStepContext) -> DialogTurnResult: if step_context.result: token_response = step_context.result if token_response and token_response.token: parts = step_context.values["command"].split(" ") command = parts[0] # display logged in users name if command == "me": client = SimpleGraphClient(token_response.token) me_info = await client.get_me() await step_context.context.send_activity( f"You are {me_info['displayName']}") # send an email elif command == "send": client = SimpleGraphClient(token_response.token) me_info = await client.get_me() response = await client.send_mail( parts[1], "Message from a bot!", f"Hi there! I had this message sent from a bot. - Your friend, {me_info['displayName']}", ) if response.status_code == 202: await step_context.context.send_activity( f"I sent a message to {parts[1]} from your account." ) else: await step_context.context.send_activity( f"Could not send a message to {parts[1]} from your " f"account.") # display carousel of 5 most recent messages elif command == "recent": client = SimpleGraphClient(token_response.token) messages = await client.get_recent_mail() attachments = [] for message in messages[:5]: message_from = message[ "from"] if "from" in message else None if message_from: subtitle = ( f"{message['from']['emailAddress']['name']} ," f"{message['from']['emailAddress']['address']}>" ) else: subtitle = "" attachments.append( CardFactory.hero_card( HeroCard( title=message["subject"], subtitle=subtitle, text=message["bodyPreview"], images=[ CardImage( url= "https://botframeworksamples.blob.core.windows.net/samples" "/OutlookLogo.jpg", alt="Outlook Logo", ) ], ))) await step_context.context.send_activity( MessageFactory.carousel(attachments)) else: await step_context.context.send_activity( f"Your token is {token_response.token}") else: await step_context.context.send_activity("We couldn't log you in.") await step_context.context.send_activity("Type anything to try again.") return await step_context.end_dialog()
async def on_turn(self, activity, headers, ip_addr): msg = activity.text.split(' ') guard = self.apply_waf(msg) if guard is not False: await self.sendmsg(activity, headers, f'{guard} is blocked') return userid = activity.from_property.id channelid = activity.channel_id if (userid, channelid) not in self.CONVREF: self.add_conversation_reference(activity) if msg[0] != 'login': if (userid, channelid) not in self.ID2USER: await self.sendmsg(activity, headers, 'user not authenticated') return elif self.ID2USER[(userid, channelid)] not in self.GAME.Player: await self.sendmsg(activity, headers, 'you have been defeated, respawn?') return T = int(time.time()) try: p = self.ID2USER[(userid, channelid)] if T - self.GAME.Player[p]['cooldown'] < 1: await self.sendmsg(activity, headers, 'slow down bro') return self.GAME.Player[p]['cooldown'] = T except: pass if msg[0] == 'login': if maxClientThres(ip_addr) is True: await self.sendmsg(activity, headers, 'max client threshold reached') return if len(msg) < 3: await self.sendmsg(activity, headers, 'usage : login <username> <password>') return if msg[1] in self.GAME.Player: await self.sendmsg(activity, headers, f'player "{msg[1]}" already exists') return if authenticateUser(msg[1], msg[2]) is True: admin = True prompt = 'admin login succeeded' else: admin = False prompt = 'user login succeeded' self.GAME.newPlayer(msg[1], T, ip_addr, admin) self.ID2USER[(userid, channelid)] = msg[1] self.USER2ID[msg[1]] = (userid, channelid) incClient(ip_addr) await self.sendmsg(activity, headers, prompt) elif msg[0] == 'infoall': if self.GAME.Player[p]['admin'] is not True: await self.sendmsg(activity, headers, 'access denied') P = [] for player in self.GAME.Player: P.append(self.GAME.infoPlayer(player)['response']) msg = MessageFactory.carousel(text='Player List', attachments=P) await self.sendmsg(activity, headers, msg) elif msg[0] == 'infoself': P = self.GAME.infoPlayer(p)['response'] msg = Activity(type=ActivityTypes.message, attachments=[P]) await self.sendmsg(activity, headers, msg) elif msg[0] == 'sendmoney': if len(msg) < 3: await self.sendmsg(activity, headers, 'usage : sendmoney <target_user> <amount>') return if self.GAME.Player[p]['admin'] is not True: await self.sendmsg(activity, headers, 'access denied') return res = self.GAME.sendmoney(msg[1], msg[2]) if res is not None: await self.process_result(activity, headers, res) elif msg[0] == 'buy': res = self.GAME.buy(p, msg[1]) if res is not None: await self.process_result(activity, headers, res) elif msg[0] == 'sell': res = self.GAME.sell(p) if res is not None: await self.process_result(activity, headers, res) elif msg[0] == 'move': res = self.GAME.move(p, T, msg[1]) if res is not None: await self.process_result(activity, headers, res) elif msg[0] == 'useitem': res = self.GAME.useitem(p, T, *msg[1:]) if res is not None: await self.process_result(activity, headers, res) elif msg[0] == 'gamble': res = await self.GAME.gamble(p) if res is not None: await self.process_result(activity, headers, res) else: await self.sendmsg(activity, headers, 'invalid') return
async def display_card_step(self, step_context: WaterfallStepContext): if step_context.context.activity.value is not None: await self.handle_special_activity(step_context) else: # Check to see if the activity is an adaptive card or a bot action response card_type = CardOptions(step_context.result.value) if ChannelSupportedCards.is_card_supported( step_context.context.activity.channel_id, card_type): if card_type == CardOptions.ADAPTIVE_CARD_BOT_ACTION: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_adaptive_card_bot_action()) ) elif card_type == CardOptions.ADAPTIVE_CARD_TEAMS_TASK_MODULE: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_adaptive_card_task_module( ))) elif card_type == CardOptions.ADAPTIVE_CARD_SUBMIT_ACTION: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_adaptive_card_submit())) elif card_type == CardOptions.HERO: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_hero_card())) elif card_type == CardOptions.THUMBNAIL: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_thumbnail_card())) elif card_type == CardOptions.RECEIPT: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_receipt_card())) elif card_type == CardOptions.SIGN_IN: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_signin_card())) elif card_type == CardOptions.CAROUSEL: # NOTE if cards are NOT the same height in a carousel, # Teams will instead display as AttachmentLayoutTypes.List await step_context.context.send_activity( MessageFactory.carousel([ CardSampleHelper.create_hero_card(), CardSampleHelper.create_hero_card(), CardSampleHelper.create_hero_card(), ])) elif card_type == CardOptions.LIST: await step_context.context.send_activity( MessageFactory.list([ CardSampleHelper.create_hero_card(), CardSampleHelper.create_hero_card(), CardSampleHelper.create_hero_card(), ])) elif card_type == CardOptions.O365: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_o365_connector_card())) elif card_type == CardOptions.TEAMS_FILE_CONSENT: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_teams_file_consent_card( TEAMS_LOGO_FILE_NAME))) elif card_type == CardOptions.ANIMATION: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_animation_card( MIND_BLOWN_GIF))) elif card_type == CardOptions.AUDIO: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_audio_card( f"{self.configuration.SERVER_URL}/{MUSIC_API}") )) elif card_type == CardOptions.VIDEO: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_video_card( CORGI_ON_CAROUSEL_VIDEO))) elif card_type == CardOptions.ADAPTIVE_UPDATE: await step_context.context.send_activity( MessageFactory.attachment( CardSampleHelper.create_adaptive_update_card())) elif card_type == CardOptions.END: # End the dialog so the host gets an EoC await step_context.context.send_activity( Activity( type=ActivityTypes.end_of_conversation, code=EndOfConversationCodes.completed_successfully, )) return DialogTurnResult(DialogTurnStatus.Complete) else: await step_context.context.send_activity( f"{card_type.value} cards are not supported in the " f"{step_context.context.activity.channel_id} channel.") return await step_context.replace_dialog(self.initial_dialog_id, "What card would you want?")