How to use ChatGPT in Microsoft Teams.(Power Automate Cloud flow)

03/11/2023

Japanese version.

Introduction of how ChatGPT replies to Teams chats using Power Automate (Crowd flow).

Steps

Get the ChatGPT API key (secret key) in beforehand.

Then create an Automated cloud flow with a When a new channel message is added Trigger.

For the trigger, set the Team and Channel you want ChatGPT to reply to.

Then set up the Initialize variable Action.

Specify APY_KEY for Name, String for Type, and API key for Value.

Set up an HTTP Action.

Set up as follows.

ParameterValue
MethodPOST
URIhttps://api.openai.com/v1/completions
Header, line 1, leftContent-Type
Header, line 1, rightapplication/json
Header, line 2, leftAuthorization
Header, line 2, rightBearer @{variables('APY_KEY')}
Body{
"model": "text-davinci-003",
"prompt": @{triggerOutputs()?['body/body/content']},
"max_tokens": 2024,
"temperature": 0,
"top_p": 1
}

Set up a Reply with a message in a channel Action.

項目
Post asFlow bot
Post inChannel
Message ID@{triggerOutputs()?['body/id']}
TeamSame Team as the Trigger.
ChannelSame Channel as the Trigger.
MessageSpecify the expression below.
trim(body('HTTP')?['choices'][0]?['text'])

This completes the flow. Enter a message on the designated channel and ChatGPT will reply. Triggers are generally time-delayed by about 5 minutes.

Overall view

Links

How to use ChatGPT.(Power Automate Cloud flow)

Links

ChatGPT Articles