예제 #1
0
파일: teams.py 프로젝트: fakegit/opsdroid
    async def teams_message_handler(self, req: Request) -> Response:
        """Handle incoming webhooks from Teams."""
        if "application/json" in req.headers["Content-Type"]:
            body = await req.json()
            _LOGGER.debug(json.dumps(body))
        else:
            return Response(status=415)

        activity = Activity().deserialize(body)

        # Cache service endpoint for channel
        teams_channel_id = teams_get_channel_id(activity)
        if teams_channel_id not in self.service_endpoints:
            self.service_endpoints[teams_channel_id] = activity.service_url
            await self.opsdroid.memory.put("teams_service_endpoints",
                                           self.service_endpoints)

        if activity.type == "message":
            message = Message(
                text=activity.text,
                user=activity.from_property.name,
                target=TurnContext.get_conversation_reference(activity),
                connector=self,
                raw_event=TurnContext(self.adapter, activity),
            )
            await self.opsdroid.parse(message)
        else:
            _LOGGER.info(
                f"Recieved {activity.type} activity which is not currently supported."
            )

        return Response(status=200)
예제 #2
0
    async def process_activity(self, logic: Callable):
        """
        Begins listening to console input.
        :param logic:
        :return:
        """
        while True:
            msg = input()
            if msg is None:
                pass
            else:
                self._next_id += 1
                activity = Activity(
                    text=msg,
                    channel_id="console",
                    from_property=ChannelAccount(id="user", name="User1"),
                    recipient=ChannelAccount(id="bot", name="Bot"),
                    conversation=ConversationAccount(id="Convo1"),
                    type=ActivityTypes.message,
                    timestamp=datetime.datetime.now(),
                    id=str(self._next_id),
                )

                activity = TurnContext.apply_conversation_reference(
                    activity, self.reference, True)
                context = TurnContext(self, activity)
                await self.run_pipeline(context, logic)
예제 #3
0
 async def process_activity(self, logic: Callable):
     """
     Begins listening to console input.
     :param logic:
     :return:
     """
     while True:
         #user's input is set as variable msg
         msg = input()
         #Nothing happens if the user inputs a blank input
         if msg is None:
             pass
         else:
             #increases _next_id value by one
             self._next_id += 1
             # creating an object for communication with the Bot. Used as an initial message for a new conversation
             activity = Activity(
                 text=msg,
                 channel_id='console',
                 #Uniquely identifies ID of user and their name
                 from_property=ChannelAccount(id='user', name='User1'),
                 #identifies the bot as recipient and their name as Bot
                 recipient=ChannelAccount(id='bot', name='Bot'),
                 #identification of the conversation
                 conversation=ConversationAccount(id='Convo1'),
                 type=ActivityTypes.message,
                 timestamp=datetime.datetime.now(),
                 id=str(self._next_id))
             #send to the bot
             activity = TurnContext.apply_conversation_reference(
                 activity, self.reference, True)
             context = TurnContext(self, activity)
             # output of the function
             #logs message from user
             await self.run_middleware(context, logic)
예제 #4
0
    async def process_activities(self, msgs, logic: Callable):
        """
        Loops through array of strings to bot

        :param msgs:
        :param logic:
        :return:
        """
        for msg in msgs:
            if msg is None:
                pass
            else:
                self._next_id += 1
                activity = Activity(text=msg,
                                    channel_id='console',
                                    from_property=ChannelAccount(id='user', name='User1'),
                                    recipient=ChannelAccount(id='bot', name='Bot'),
                                    conversation=ConversationAccount(id='Convo1'),
                                    type=ActivityTypes.message,
                                    timestamp=datetime.datetime.now(),
                                    id=str(self._next_id))

                activity = TurnContext.apply_conversation_reference(activity, self.reference, True)
                context = TurnContext(self, activity)
                print(context.get_conversation_reference(activity))

                await self.run_middleware(context, logic)