-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #424 from finos/vaibhav-upload-file-feature
Vaibhav upload file feature
- Loading branch information
Showing
13 changed files
with
341 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...n/java/org/finos/springbot/workflow/java/resolvers/ChatButtonWorkflowResolverFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.finos.springbot.workflow.java.resolvers; | ||
|
||
import java.util.Optional; | ||
|
||
import org.finos.springbot.workflow.annotations.ChatButton; | ||
import org.finos.springbot.workflow.java.mapping.ChatHandlerExecutor; | ||
|
||
/** | ||
* Get chat button detail in controller | ||
* @author mankvaia | ||
* | ||
*/ | ||
public class ChatButtonWorkflowResolverFactory implements WorkflowResolverFactory { | ||
|
||
|
||
private final class ChatButtonWorkflowResolver extends AbstractClassWorkflowResolver { | ||
private final ChatHandlerExecutor che; | ||
|
||
private ChatButtonWorkflowResolver(ChatHandlerExecutor che) { | ||
this.che = che; | ||
} | ||
|
||
@Override | ||
public Optional<Object> resolve(Class<?> cl) { | ||
if (ChatButton.class.isAssignableFrom(cl) && che.getOriginatingMapping().getMapping() instanceof ChatButton) { | ||
|
||
return Optional.of((ChatButton) che.getOriginatingMapping().getMapping()); | ||
|
||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public boolean canResolve(Class<?> cl) { | ||
return resolve(cl).isPresent(); | ||
} | ||
} | ||
|
||
@Override | ||
public WorkflowResolver createResolver(ChatHandlerExecutor che) { | ||
return new ChatButtonWorkflowResolver(che); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...oot-starter/src/main/java/org/finos/springbot/teams/handlers/SimpleAttachmentHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.finos.springbot.teams.handlers; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.finos.springbot.workflow.response.AttachmentResponse; | ||
|
||
import com.microsoft.bot.schema.Attachment; | ||
import com.microsoft.bot.schema.teams.FileConsentCard; | ||
|
||
public class SimpleAttachmentHandler implements AttachmentHandler { | ||
|
||
public Attachment formatAttachment(AttachmentResponse ar) { | ||
|
||
try { | ||
Attachment a = new Attachment(); | ||
String fileName = ar.getName().replaceAll("\\s+", "_") + "." + ar.getExtension(); | ||
File f = null; | ||
f = File.createTempFile("temp", fileName); | ||
Files.write(f.toPath(), ar.getAttachment()); | ||
|
||
Map<String, String> consentContext = new HashMap<>(); | ||
consentContext.put("filename", fileName); | ||
consentContext.put("filepath", f.getAbsolutePath()); | ||
|
||
FileConsentCard fileCard = new FileConsentCard(); | ||
fileCard.setDescription("This is the file I want to send you"); | ||
fileCard.setSizeInBytes(ar.getAttachment().length); | ||
fileCard.setAcceptContext(consentContext); | ||
fileCard.setDeclineContext(consentContext); | ||
|
||
a.setContent(fileCard); | ||
a.setName(fileName); | ||
a.setContentType(FileConsentCard.CONTENT_TYPE); | ||
return a; | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.