async def on_message_activity(self, turn_context: TurnContext): image_url_list = [] host_page_url_list = [] host_page_name_list = [] if turn_context.activity.attachments: for attachment in turn_context.activity.attachments: attachment_info = await self._download_attachment_and_write( attachment) image_url_list, host_page_url_list, host_page_name_list = self.bing_vision_api( attachment_info['filename']) for i in range(len(host_page_url_list)): await turn_context.send_activity( MessageFactory.content_url(url=image_url_list[i], content_type='image/jpg', text=host_page_name_list[i])) await turn_context.send_activity( MessageFactory.text(text=host_page_url_list[i])) elif turn_context.activity.text: image_url_list, host_page_url_list, host_page_name_list = self.bing_image_api( turn_context.activity.text) for i in range(len(host_page_url_list)): await turn_context.send_activity( MessageFactory.content_url(url=image_url_list[i], content_type='image/jpg', text=host_page_name_list[i])) await turn_context.send_activity( MessageFactory.text(text=host_page_url_list[i]))
def test_should_return_a_content_url(self): activity = MessageFactory.content_url('https://example.com/content', 'content-type') assert_message(activity) assert_attachments(activity, 1, ['content-type']) assert activity.attachments[0].content_url == 'https://example.com/content', \ 'invalid attachment[0].content_url.'
def test_should_return_a_content_url(self): activity = MessageFactory.content_url("https://example.com/content", "content-type") assert_message(activity) assert_attachments(activity, 1, ["content-type"]) assert (activity.attachments[0].content_url == "https://example.com/content" ), "invalid attachment[0].content_url."
async def __call__(self, text, image_url=None, *args, **kwargs): if image_url: msg = MessageFactory.content_url(url=image_url, content_type="image/" + image_url[-3:], text=text) else: msg = MessageFactory.text(text) await self.turn_context.send_activity(msg)
def test_should_return_a_content_url_with_a_name_text_speak_and_input_hint( self): activity = MessageFactory.content_url('https://example.com/content', 'content-type', 'file name', 'test1', 'test2', InputHints.ignoring_input) assert_message(activity) assert_attachments(activity, 1, ['content-type']) assert activity.attachments[0].content_url == 'https://example.com/content', \ 'invalid attachment[0].content_url.' assert activity.attachments[ 0].name == 'file name', 'invalid attachment[0].name.' 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.'
async def send_message(req: Request) -> Response: try: credentials = MicrosoftAppCredentials(CONFIG.APP_ID, CONFIG.APP_PASSWORD) client = ConnectorClient(credentials, 'https://smba.trafficmanager.net/fr/') teams_client = TeamsConnectorClient(credentials, 'https://smba.trafficmanager.net/fr/') teams_channels = teams_client.teams.get_teams_channels('19:[email protected]') general_channel = next(channel for channel in teams_channels.conversations if channel.name is None) conversation_parameters = ConversationParameters( is_group=True, channel_data={"channel": {"id": general_channel.id}}, activity=MessageFactory.content_url('https://picsum.photos/200/300', 'image/png'), ) client.conversations.create_conversation(conversation_parameters) return Response(status=HTTPStatus.OK) except Exception: traceback.print_exc()
def test_should_return_a_content_url_with_a_name_text_speak_and_input_hint( self): activity = MessageFactory.content_url( "https://example.com/content", "content-type", "file name", "test1", "test2", InputHints.ignoring_input, ) assert_message(activity) assert_attachments(activity, 1, ["content-type"]) assert (activity.attachments[0].content_url == "https://example.com/content" ), "invalid attachment[0].content_url." assert (activity.attachments[0].name == "file name" ), "invalid attachment[0].name." 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."