cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Bookmark
|
Subscribe
|
4408
Views
5
Helpful
5
Replies

webex bot post contents of an email into a room

Richard Lucht
Level 1
Level 1

I am interested in using webex bots or anything else that would take a body of an email and post it into a webex room.  We have automated emails that come from a system and I would prefer those to be in a webex space that would get noticed sooner.

1 Accepted Solution

Here's a version of your script that variable-izes things:

url = 'https://webexapis.com/v1/messages'

message = '**Test Message**'
roomId = 'Y2lzY29zcGFyazovL3Vz***********************************************L1mYzRhYTM2YjVi'
token = 'NGEyYjhlMGItZjg1*********************************************17ae04-c4aa-4444-9f54-4bebcee07305'

payload = {
    'roomId': roomId,
    'markdown': message
}

headers = {
  'Authorization': f'Bearer { token }',
  'Content-Type': 'application/json'
}

response = requests.request( 'POST', url, headers = headers, json = payload )

print( response.text.encode( 'utf8'  ))

View solution in original post

5 Replies 5

nmorrow
Cisco Employee
Cisco Employee

Hello,

 

Bot tokens can be used to message Webex Teams spaces that the bot has been added to using the POST method for the /meetings endpoint, documented at https://developer.webex.com/docs/api/v1/messages/create-a-message. 

I have been playing with the bots and i have a python script that will post what i type in the script but i am having some trouble with adding a variable.  I want the message to be a variable that I can input later.

 

import requests


payload = "{\r\n  \"roomId\": \"Y2lzY29zcGFyazovL3Vz***********************************************L1mYzRhYTM2YjVi\",\r\n  \"markdown\": \"  Message   \"\r\n}"
headers = {
  'Authorization''Bearer NGEyYjhlMGItZjg1*********************************************17ae04-c4aa-4444-9f54-4bebcee07305',
  'Content-Type''application/json'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))

 

Here's a version of your script that variable-izes things:

url = 'https://webexapis.com/v1/messages'

message = '**Test Message**'
roomId = 'Y2lzY29zcGFyazovL3Vz***********************************************L1mYzRhYTM2YjVi'
token = 'NGEyYjhlMGItZjg1*********************************************17ae04-c4aa-4444-9f54-4bebcee07305'

payload = {
    'roomId': roomId,
    'markdown': message
}

headers = {
  'Authorization': f'Bearer { token }',
  'Content-Type': 'application/json'
}

response = requests.request( 'POST', url, headers = headers, json = payload )

print( response.text.encode( 'utf8'  ))

That is one command missing. it need to import the request module.  

import requests as requests

Thank you that worked

 

I added message = (input_data['message']) this so I can handle inputs.  That is a bit closer to what I want.  Thank you