Modules@robinpath/teams
teams

@robinpath/teams

0.1.1Node.jsPublic

Teams module for RobinPath.

Teams

Teams module for RobinPath.

Package: @robinpath/teams | Category: Messaging | Type: Integration

Authentication

teams.setToken "eyJ0xxx"

Call this once at the start of your script before using any other function. Credentials persist for the duration of the script execution.

Use Cases

Use the teams module when you need to:

  • Send a message to a Teams channel. -- Use teams.sendChannel to perform this operation
  • Send a message in a 1:1 or group chat. -- Use teams.sendChat to perform this operation
  • Reply to a message in a channel. -- Use teams.replyToMessage to perform this operation
  • List all teams the user has joined. -- Use teams.listTeams to perform this operation
  • List channels in a team. -- Use teams.listChannels to perform this operation

Quick Reference

FunctionDescriptionReturns
setTokenSet the Microsoft Graph API access token.Confirmation message.
sendChannelSend a message to a Teams channel.Created message object.
sendChatSend a message in a 1:1 or group chat.Created message object.
replyToMessageReply to a message in a channel.Created reply message.
listTeamsList all teams the user has joined.Object with value array of teams.
listChannelsList channels in a team.Object with value array of channels.
getMessagesGet messages from a channel.Object with value array of messages.
createChannelCreate a new channel in a team.Created channel object.
listChatsList all chats for the current user.Object with value array of chats.
sendWebhookSend a message via an incoming webhook URL.Confirmation message.

Functions

setToken

Set the Microsoft Graph API access token.

Module: teams | Returns: string -- Confirmation message.

teams.setToken "eyJ0xxx"
ParameterTypeRequiredDescription
tokenstringYesOAuth2 access token with Teams permissions

sendChannel

Send a message to a Teams channel.

Module: teams | Returns: object -- Created message object.

teams.sendChannel "team-id" "channel-id" "Hello team!"
ParameterTypeRequiredDescription
teamIdstringYesTeam ID
channelIdstringYesChannel ID
messagestringYesMessage content (supports HTML)

sendChat

Send a message in a 1:1 or group chat.

Module: teams | Returns: object -- Created message object.

teams.sendChat "chat-id" "Hey there!"
ParameterTypeRequiredDescription
chatIdstringYesChat ID
messagestringYesMessage content (supports HTML)

replyToMessage

Reply to a message in a channel.

Module: teams | Returns: object -- Created reply message.

teams.replyToMessage "team-id" "channel-id" "msg-id" "Thanks!"
ParameterTypeRequiredDescription
teamIdstringYesTeam ID
channelIdstringYesChannel ID
messageIdstringYesMessage ID to reply to
replystringYesReply content

listTeams

List all teams the user has joined.

Module: teams | Returns: object -- Object with value array of teams.

teams.listTeams
ParameterTypeRequiredDescription
(none)NoCall with no arguments

listChannels

List channels in a team.

Module: teams | Returns: object -- Object with value array of channels.

teams.listChannels "team-id"
ParameterTypeRequiredDescription
teamIdstringYesTeam ID

getMessages

Get messages from a channel.

Module: teams | Returns: object -- Object with value array of messages.

teams.getMessages "team-id" "channel-id" {"top":20}
ParameterTypeRequiredDescription
teamIdstringYesTeam ID
channelIdstringYesChannel ID
optionsobjectNoOptions: top (number of messages)

createChannel

Create a new channel in a team.

Module: teams | Returns: object -- Created channel object.

teams.createChannel "team-id" "New Channel" {"description":"A new channel"}
ParameterTypeRequiredDescription
teamIdstringYesTeam ID
displayNamestringYesChannel name
optionsobjectNoOptions: description, membershipType (standard

listChats

List all chats for the current user.

Module: teams | Returns: object -- Object with value array of chats.

teams.listChats
ParameterTypeRequiredDescription
(none)NoCall with no arguments

sendWebhook

Send a message via an incoming webhook URL.

Module: teams | Returns: string -- Confirmation message.

teams.sendWebhook "https://outlook.office.com/webhook/xxx" "Alert: Build passed!"
ParameterTypeRequiredDescription
webhookUrlstringYesIncoming webhook URL
messagestringYesMessage text
optionsobjectNoOptions: title, themeColor, sections

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Teams: token not configured. Call teams.setToken first.Check the error message for details
Microsoft Graph API error (${res.status}): ${text}Check the error message for details
teams.setToken requires a token.Check the error message for details
teams.sendChannel requires teamId, channelId, and message.Check the error message for details
teams.sendChat requires chatId and message.Check the error message for details
teams.replyToMessage requires teamId, channelId, messageId, and reply.Check the error message for details
teams.listChannels requires a teamId.Check the error message for details
teams.getMessages requires teamId and channelId.Check the error message for details
@desc "Send channel and validate result"
do
  set $result as teams.sendChannel "team-id" "channel-id" "Hello team!"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate Teams

Retrieve all items and loop through them.

@desc "Setup authentication"
do
  teams.setToken $token
enddo

@desc "List teams and iterate results"
do
  set $result as teams.listTeams
  each $item in $result
    print $item
  end
enddo

2. Create a new item with sendChannel

Create a new resource and capture the result.

@desc "Setup authentication"
do
  teams.setToken $token
enddo

@desc "Send channel"
do
  set $result as teams.sendChannel "team-id" "channel-id" "Hello team!"
  print "Created: " + $result
enddo

3. Check before creating

List existing items and only create if needed.

@desc "Setup authentication"
do
  teams.setToken $token
enddo

@desc "List teams and send channel"
do
  set $existing as teams.listTeams
  if $existing == null
    teams.sendChannel "team-id" "channel-id" "Hello team!"
    print "Item created"
  else
    print "Item already exists"
  end
enddo

4. Multi-step Teams workflow

Chain multiple teams operations together.

@desc "Setup authentication"
do
  teams.setToken $token
enddo

@desc "Send channel, send chat, and more"
do
  set $r_sendChannel as teams.sendChannel "team-id" "channel-id" "Hello team!"
  set $r_sendChat as teams.sendChat "chat-id" "Hey there!"
  set $r_replyToMessage as teams.replyToMessage "team-id" "channel-id" "msg-id" "Thanks!"
  print "All operations complete"
enddo

5. Safe sendChannel with validation

Check results before proceeding.

@desc "Setup authentication"
do
  teams.setToken $token
enddo

@desc "Send channel and validate result"
do
  set $result as teams.sendChannel "team-id" "channel-id" "Hello team!"
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • slack -- Slack module for complementary functionality
  • discord -- Discord module for complementary functionality
  • telegram -- Telegram module for complementary functionality
  • whatsapp -- WhatsApp module for complementary functionality
  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/teams

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size5.1 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago